Example #1
0
        private static IDictionary <string, string> CreateSendParam(
            string businessId, string templateId, IDictionary <string, string> variables, string to, string countryCallingCode)
        {
            var paramDict = new Dictionary <string, string>()
            {
                ["nonce"]     = ParamUtils.CreateNonce(),
                ["timestamp"] = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString(),
                ["version"]   = "v2",

                ["secretId"]   = SECRET_ID,
                ["businessId"] = businessId,

                ["templateId"] = templateId,
                ["mobile"]     = to,

                ["paramType"] = "json",
                ["params"]    = ParamUtils.SerializeVariables(variables)
            };

            // 如果要发送国际短信,则需要指明国际电话区号。如果不是国际短信,则不要指定此参数
            if (!string.IsNullOrWhiteSpace(countryCallingCode))
            {
                paramDict["internationalCode"] = countryCallingCode;
            }


            // 在最后一步生成此次请求的签名
            paramDict["signature"] = ParamUtils.GenSignature(SECRET_KEY, paramDict);

            return(paramDict);
        }
Example #2
0
        static void TestGenSignature()
        {
            var secretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            var paramDict = new Dictionary <string, string>
            {
                ["nonce"]      = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                ["timestamp"]  = "1598889600000",
                ["version"]    = "v2",
                ["secretId"]   = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                ["businessId"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                ["templateId"] = "xxxxx",
                ["mobile"]     = "xxxxxxxxxxx",
                ["paramType"]  = "json",
                ["params"]     = @"{""code"":""123456""}"
            };

            var expect = "22d28d2ce543e8c97bd12f078a30784b";

            var sign = ParamUtils.GenSignature(secretKey, paramDict);

            if (String.Equals(expect, sign))
            {
                Console.WriteLine("signature test: pass");
            }
            else
            {
                Console.WriteLine(sign);
                Console.WriteLine("signature test: fail");
            }
        }
Example #3
0
        /// <summary>
        /// 构建验证码校验请求的参数
        /// </summary>
        private static Dictionary <string, string> CreateVerifyParam(string businessId, string requestId, string code)
        {
            var paramDict = new Dictionary <string, string>()
            {
                ["nonce"]     = ParamUtils.CreateNonce(),
                ["timestamp"] = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString(),
                ["version"]   = "v2",

                ["secretId"]   = SECRET_ID,
                ["businessId"] = businessId,

                ["requestId"] = requestId,
                ["code"]      = code
            };

            // 在最后一步生成此次请求的签名
            paramDict["signature"] = ParamUtils.GenSignature(SECRET_KEY, paramDict);

            return(paramDict);
        }
Example #4
0
        /// <summary>
        /// 构建发送验证码短信的请求参数:指明由易盾生成验证码
        /// </summary>
        private static Dictionary <String, String> CreateSendParam(
            String businessId, String templateId, IDictionary <string, string> variables, String to, String countryCallingCode)
        {
            var paramDict = new Dictionary <string, string>
            {
                ["nonce"]     = ParamUtils.CreateNonce(),
                ["timestamp"] = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString(),
                ["version"]   = "v2",

                ["secretId"]   = SECRET_ID,
                ["businessId"] = businessId,

                ["templateId"] = templateId,
                ["mobile"]     = to,

                ["paramType"] = "json",
                ["params"]    = ParamUtils.SerializeVariables(variables),

                // 指明由易盾生成验证码:
                // codeName 表示目标模板内容中,验证码的占位符变量名。如,模板内容为 “您的验证码为${code},5分钟内有效,请勿泄露。”,则 codeName 的值应为 code
                ["codeName"] = "code",
                // codeLen 表示验证码的数字个数
                ["codeLen"] = "6",
                // codeValidSec 表示验证码的有效期。单位:秒
                ["codeValidSec"] = "300"
            };

            // 如果要发送国际短信,则需要指明国际电话区号。如果不是国际短信,则不要指定此参数
            if (!string.IsNullOrWhiteSpace(countryCallingCode))
            {
                paramDict["internationalCode"] = countryCallingCode;
            }

            // 在最后一步生成此次请求的签名
            paramDict["signature"] = ParamUtils.GenSignature(SECRET_KEY, paramDict);

            return(paramDict);
        }