Пример #1
0
        protected bool Send(string phone, string tplId, NameValueCollection nvc, string code)
        {
            SMSDB db = new SMSDB();

            SMSDB.TemplateData templateData = db.GetTemplate(tplId);
            string             access_token = null;

            //查看access_token是否过期
            if (templateData.expire < DateTime.Now.Ticks)
            {
                CCTokenResult tokenResult = GetCCToken(templateData.app_id, templateData.app_secret);
                if (tokenResult.res_code == "0")
                {
                    db.UpdateToken(tplId, tokenResult.access_token, DateTime.Now.Ticks + tokenResult.expires_in * 1000);
                    access_token = tokenResult.access_token;
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                access_token = templateData.access_token;
            }
            return(Send(templateData.app_id, templateData.app_secret, access_token, phone, templateData.tpl_id, BuildParameter(nvc), code));
        }
Пример #2
0
        public CCTokenResult GetCCToken(string appid, string appScrect)
        {
            string        data      = string.Format("grant_type=client_credentials&app_id={0}&app_secret={1}", appid, appScrect);
            string        tokenJson = PostData("https://oauth.api.189.cn/emp/oauth2/v3/access_token", data);
            CCTokenResult result    = null;

            if (tokenJson != null)
            {
                LitJson.JsonData json = LitJson.JsonMapper.ToObject(tokenJson);
                result = new CCTokenResult();
                result.access_token = (string)json["access_token"];
                result.expires_in   = (int)json["expires_in"];
                result.res_code     = (string)json["res_code"];
                result.res_message  = (string)json["res_message"];
            }
            return(result);
        }