private ExpSMSResponse GetMsgFromDicData(Dictionary<string, object> data) { ExpSMSResponse expr = new ExpSMSResponse("0", "无"); foreach (KeyValuePair<string, object> item in data) { if (item.Key == "statusCode") { expr.statusCode = item.Value.ToString(); } if (item.Key == "statusMsg") { expr.statusMsg = item.Value.ToString(); } } return expr; }
//statusCode=000000;statusMsg=成功;data={TemplateSMS={dateCreated=20160729163137;smsMessageSid=cdd8c497980a4a3d9fc8e9ce727f86e5;};}; public ExpSMSResponse SendSMS(string to, string templateId, string[] data) { ExpSMSResponse expRes = new ExpSMSResponse(); if (IsSMS == 1) { string ret = ""; CCPRestSDK.CCPRestSDK api = new CCPRestSDK.CCPRestSDK(); //ip格式如下,不带https:// bool isInit = api.init(RestURL, RestPort); api.setAccount(AcountSID, AuthToken); api.setAppId(AppID); try { if (isInit) { Dictionary<string, object> retData = api.SendTemplateSMS(to, templateId, data); // ret = getDictionaryData(retData); expRes = GetMsgFromDicData(retData); } else { ret = "初始化失败"; expRes = new ExpSMSResponse("0", "初始化失败"); } return expRes; } catch (Exception exc) { ret = exc.Message; expRes = new ExpSMSResponse("-1", exc.Message); return expRes; } } else { expRes.statusCode = "-1"; expRes.statusMsg = "未开启短信发送!"; return expRes; } }