public async Task <ChinaMobileHttpRsp> SendTemplateSms(ChinaMobileHttpTemplateSms input) { var dic = new Dictionary <string, string> { { "ecName", input.EcName }, { "apId", input.ApId }, { "secretKey", input.SecretKey }, { "templateId", input.TemplateId }, { "mobiles", string.Join(",", input.Mobiles) }, { "params", JsonConvert.SerializeObject(input.Params) }, { "sign", input.Sign }, { "addSerial", input.AddSerial } }; var sb = new StringBuilder(); sb.Append(dic["ecName"]); sb.Append(dic["apId"]); sb.Append(dic["secretKey"]); sb.Append(dic["templateId"]); sb.Append(dic["mobiles"]); sb.Append(dic["params"]); sb.Append(dic["sign"]); sb.Append(dic["addSerial"]); dic.Add("mac", Md5(sb.ToString())); var data = JsonConvert.SerializeObject(dic); var encodeData = Base64(data); var result = await ApiCallerHelper.Execute <ChinaMobileHttpRsp>(input.Url, HttpMethod.Post, encodeData); return(result); }
public async Task <SmsRsp> SendTemplateSms(string[] mobiles, string templateId, Dictionary <string, string> parameters, string sign = "") { var result = new SmsRsp(); try { var input = new ChinaMobileHttpTemplateSms { EcName = _options.EcName, ApId = _options.AppId, SecretKey = _options.AppSecret, Mobiles = mobiles, TemplateId = templateId, Params = parameters.Values.ToArray(), Sign = string.IsNullOrWhiteSpace(sign) ? _options.Sign : sign, AddSerial = _options.AddSerial, Url = _options.TmpSubmitUrl }; var rsp = await _client.SendTemplateSms(input); result.Success = rsp.Success; result.RspCode = rsp.Rspcod; result.RspMsg = EnumHelper.GetEnumDesc <ChinaMobileHttpRspCode>(rsp.Rspcod); } catch (Exception ex) { result.Success = false; result.RspCode = string.Empty; result.RspMsg = ex.Message; } return(result); }