using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using ZTImage.Log; namespace DetectorUtils.Utilitys { public class SmsHelper { private const String url = "http://dingxin.market.alicloudapi.com/dx/sendSms"; private const String method = "POST"; private const String appcode = "f279855887224d72884058ef52063e68"; //模板:[创富器]机器号:#mid#,问题:#qcontent# public static bool Send(string mobile, string machineID,string question) { machineID = machineID.Replace(',', ','); question=question.Replace(',', ','); //todo:如果不是我的号,就验证一下 String querys = $"?mobile={mobile}¶m=mid%3A{ZTImage.Text.Coding.EncodeURI(machineID)},qcontent%3A{ZTImage.Text.Coding.EncodeURI(question)}&tpl_id=TP19070631"; Dictionary headers = new Dictionary() { { "Authorization",$"APPCODE {appcode}"} }; try { string content = ZTImage.HttpEx.SyncPost(url + querys, headers); if (string.IsNullOrEmpty(content)) { Trace.Error("send sms 返回数据为空"); return false; } Dictionary json = ZTImage.Json.JsonParser.ToDictionary(content); if (json==null) { Trace.Error("send sms return 非有效json,"+content); return false; } if (!json.ContainsKey("return_code")||json["return_code"]==null) { Trace.Error("send sms return 不包含return_code或return_code为空," + content); return false; } string code=json["return_code"].ToString(); if (!code.Equals("00000", StringComparison.OrdinalIgnoreCase)) { Trace.Error("send sms 失败," + content); return false; } /* * //success { "return_code": "00000", "order_id": "ALY15........825" } */ return true; } catch (Exception ex) { Trace.Error("send sms error", ex); return false; } } } }