/// <summary> /// Send a tts voice. /// </summary> /// <param name="nationCode">nation dialing code, e.g. China is 86, USA is 1</param> /// <param name="phoneNumber">phone number</param> /// <param name="templateId">template id</param> /// <param name="parameters">template parameters</param> /// <param name="playtimes">playtimes, optional, max is 3, default is 2</param> /// <param name="ext">ext field, content will be returned by server as it is</param> /// <returns>TtsVoiceSenderResult</returns> public TtsVoiceSenderResult send(string nationCode, string phoneNumber, int templateId, string[] parameters, int playtimes, string ext) { long random = SmsSenderUtil.getRandom(); long now = SmsSenderUtil.getCurrentTime(); JSONObjectBuilder body = new JSONObjectBuilder() .Put("tel", (new JSONObjectBuilder()).Put("nationcode", nationCode).Put("mobile", phoneNumber).Build()) .Put("tpl_id", templateId) .PutArray("params", parameters) .Put("playtimes", playtimes) .Put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now, phoneNumber)) .Put("time", now) .Put("ext", !String.IsNullOrEmpty(ext) ? ext : ""); HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url) .addHeader("Conetent-Type", "application/json") .addQueryParameter("sdkappid", this.appid) .addQueryParameter("random", random) .setConnectionTimeout(60 * 1000) .setRequestTimeout(60 * 1000) .setBody(body.Build().ToString()); // May throw HttpRequestException HTTPResponse res = httpclient.fetch(req); // May throw HTTPException handleError(res); TtsVoiceSenderResult result = new TtsVoiceSenderResult(); // May throw JSONException result.parseFromHTTPResponse(res); return(result); }
/// <summary> /// Send a SMS messages to multiple phones at once. /// </summary> /// <param name="type">Send a SMS messages to multiple phones at once.</param> /// <param name="nationCode">nation dialing code, e.g. China is 86, USA is 1</param> /// <param name="phoneNumbers">phone number array</param> /// <param name="msg">SMS message content</param> /// <param name="extend">extend field, default is empty string</param> /// <param name="ext">ext field, content will be returned by server as it is</param> /// <returns>SmsMultiSenderResult</returns> public SmsMultiSenderResult send(int type, string nationCode, List <string> phoneNumbers, string msg, string extend, string ext) { long random = SmsSenderUtil.getRandom(); long now = SmsSenderUtil.getCurrentTime(); JSONObjectBuilder body = new JSONObjectBuilder() .Put("tel", toTel(nationCode, phoneNumbers)) .Put("type", type) .Put("msg", msg) .Put("sig", SmsSenderUtil.calculateSignature(appkey, random, now, phoneNumbers.ToArray())) .Put("time", now) .Put("extend", !String.IsNullOrEmpty(extend) ? extend : "") .Put("ext", !String.IsNullOrEmpty(ext) ? ext : ""); HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url) .addHeader("Conetent-Type", "application/json") .addQueryParameter("sdkappid", this.appid) .addQueryParameter("random", random) .setConnectionTimeout(60 * 1000) .setRequestTimeout(60 * 1000) .setBody(body.Build().ToString()); // May throw HttpRequestException HTTPResponse res = httpclient.fetch(req); // May throw HTTPException handleError(res); SmsMultiSenderResult result = new SmsMultiSenderResult(); // May throw JSONException result.parseFromHTTPResponse(res); return(result); }
private HTTPResponse pull(int type, string nationCode, string mobile, long beginTime, long endTime, int max) { long random = SmsSenderUtil.getRandom(); long now = SmsSenderUtil.getCurrentTime(); JSONObjectBuilder body = new JSONObjectBuilder(); body.Put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now)) .Put("type", type) .Put("time", now) .Put("max", max) .Put("begin_time", beginTime) .Put("end_time", endTime) .Put("nationcode", nationCode) .Put("mobile", mobile); HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url) .addHeader("Conetent-Type", "application/json") .addQueryParameter("sdkappid", this.appid) .addQueryParameter("random", random) .setConnectionTimeout(60 * 1000) .setRequestTimeout(60 * 10000) .setBody(body.Build().ToString()); // May throw HttpRequestException HTTPResponse res = httpclient.fetch(req); // May throw HTTPException handleError(res); return(res); }
/// <summary> /// Send a file voice. /// </summary> /// <param name="fileContent">file content bytes</param> /// <param name="contentType">file content type</param> /// <returns>VoiceFileUploaderResult</returns> public VoiceFileUploaderResult upload(byte[] fileContent, ContentType contentType) { long random = SmsSenderUtil.getRandom(); long now = SmsSenderUtil.getCurrentTime(); string fileSha1Sum = SmsSenderUtil.sha1sum(fileContent); string auth = SmsSenderUtil.calculateAuth(this.appkey, random, now, fileSha1Sum);; string type; if (contentType == ContentType.WAV) { type = "audio/wav"; } else { type = "audio/mpeg"; } Encoding iso = Encoding.GetEncoding("ISO-8859-1"); HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url) .addHeader("Content-Type", type) .addHeader("x-content-sha1", fileSha1Sum) .addHeader("Authorization", auth) .addQueryParameter("sdkappid", this.appid) .addQueryParameter("random", random) .addQueryParameter("time", now) .setConnectionTimeout(60 * 1000) .setRequestTimeout(60 * 1000) .setBody(iso.GetString(fileContent)) .setBodyEncoding(iso); // May throw HttpRequestException HTTPResponse res = httpclient.fetch(req); // May throw HTTPException handleError(res); VoiceFileUploaderResult result = new VoiceFileUploaderResult(); // May throw JSONException result.parseFromHTTPResponse(res); return(result); }
public static long getRandom() { return((new Random((int)SmsSenderUtil.getCurrentTime())).Next() % 900000L + 100000L); }