asmrobot
2019-10-14 730fe7ea65bcadbe235e40bb54b2410d14495267
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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}&param=mid%3A{ZTImage.Text.Coding.EncodeURI(machineID)},qcontent%3A{ZTImage.Text.Coding.EncodeURI(question)}&tpl_id=TP19070631";
 
            Dictionary<string, string> headers = new Dictionary<string, string>() {
                { "Authorization",$"APPCODE {appcode}"}
            };
 
            try
            {
                string content = ZTImage.HttpEx.SyncPost(url + querys, headers);
                if (string.IsNullOrEmpty(content))
                {
                    Trace.Error("send sms 返回数据为空");
                    return false;
                }
 
                Dictionary<string, object> 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;
            }
 
        }
    }
}