Example #1
0
        public string GetSMSCode(string phone)
        {
            object obj = new
            {
                timestamp = (DateTime.Now - DateTime.Parse("1970-01-01 00:00:00")).TotalMilliseconds,
                mobile    = phone
            };
            requestModel req = new requestModel()
            {
                pId            = System.Configuration.ConfigurationManager.ConnectionStrings["pid"].ConnectionString,
                encryptContent = AESHelper.AESEncrypt(JsonConvert.SerializeObject(obj))
            };

            try
            {
                string res = HttpWebResponseUtility.CreatePostDataResponse(System.Configuration.ConfigurationManager.ConnectionStrings["url"].ConnectionString +
                                                                           System.Configuration.ConfigurationManager.ConnectionStrings["getsmscode"].ConnectionString, JsonConvert.SerializeObject(req));
                responseModel response = JsonConvert.DeserializeObject <responseModel>(res);
                if (response.status.Equals("success"))
                {
                    AESHelper.AESDecrypt(response.encryptionBody);
                    SMSModel smsmodel = JsonConvert.DeserializeObject <SMSModel>(AESHelper.AESDecrypt(response.encryptionBody));
                    return(smsmodel.sms_code);
                }
                else
                {
                    throw new Exception(response.message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        public string getQR(QRModel qr)
        {
            qr.timestamp = (DateTime.Now - DateTime.Parse("1970-01-01 00:00:00")).TotalMilliseconds;
            requestModel req = new requestModel()
            {
                pId            = System.Configuration.ConfigurationManager.ConnectionStrings["pid"].ConnectionString,
                encryptContent = AESHelper.AESEncrypt(JsonConvert.SerializeObject(qr))
            };

            try
            {
                string res = HttpWebResponseUtility.CreatePostDataResponse(System.Configuration.ConfigurationManager.ConnectionStrings["url"].ConnectionString +
                                                                           System.Configuration.ConfigurationManager.ConnectionStrings["getqr"].ConnectionString, JsonConvert.SerializeObject(req));
                responseModel response = JsonConvert.DeserializeObject <responseModel>(res);
                if (response.status.Equals("success"))
                {
                    return(response.qr_image);
                }
                else
                {
                    throw new Exception(response.message);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #3
0
        public UserInfo getUserInfo(string openid)
        {
            var          obj = new { timestamp = (DateTime.Now - DateTime.Parse("1970-01-01 00:00:00")).TotalMilliseconds, openId = openid };
            requestModel req = new requestModel()
            {
                pId            = System.Configuration.ConfigurationManager.ConnectionStrings["pid"].ConnectionString,
                encryptContent = AESHelper.AESEncrypt(JsonConvert.SerializeObject(obj))
            };

            try
            {
                string res = HttpWebResponseUtility.CreatePostDataResponse(System.Configuration.ConfigurationManager.ConnectionStrings["url"].ConnectionString +
                                                                           System.Configuration.ConfigurationManager.ConnectionStrings["userInfo"].ConnectionString, JsonConvert.SerializeObject(req));
                log.Debug("获取用户信息:" + res);
                responseModel response = JsonConvert.DeserializeObject <responseModel>(res);
                if (response.status.Equals("success"))
                {
                    log.Debug("解析用户信息:" + AESHelper.AESDecrypt(response.encryptionBody));
                    UserInfo userInfo = JsonConvert.DeserializeObject <UserInfo>(AESHelper.AESDecrypt(response.encryptionBody));
                    return(userInfo);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #4
0
        public bool ChangeEmail(string openId, string email)
        {
            object obj = new
            {
                timestamp = (DateTime.Now - DateTime.Parse("1970-01-01 00:00:00")).TotalMilliseconds,
                email,
                openId
            };
            requestModel req = new requestModel()
            {
                pId            = System.Configuration.ConfigurationManager.ConnectionStrings["pid"].ConnectionString,
                encryptContent = AESHelper.AESEncrypt(JsonConvert.SerializeObject(obj))
            };

            try
            {
                string res = HttpWebResponseUtility.CreatePostDataResponse(System.Configuration.ConfigurationManager.ConnectionStrings["url"].ConnectionString +
                                                                           System.Configuration.ConfigurationManager.ConnectionStrings["changeemail"].ConnectionString, JsonConvert.SerializeObject(req));
                responseModel response = JsonConvert.DeserializeObject <responseModel>(res);
                if (response.status.Equals("success"))
                {
                    return(true);
                }
                else
                {
                    throw new Exception(response.message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
        /// <summary>
        /// 获取公众号预授权码
        /// </summary>
        /// <param name="component_access_token">接口调用凭据</param>
        /// <returns></returns>
        public static string GetPreAuthCode(string component_access_token)
        {
            var      data     = new { component_appid = AppID };
            string   res      = HttpWebResponseUtility.CreatePostDataResponse("https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=" + component_access_token, JsonConvert.SerializeObject(data));
            ResModel resModel = JsonConvert.DeserializeObject <ResModel>(res);

            if (resModel.errcode.HasValue)
            {
                return("");
            }
            else
            {
                return(resModel.pre_auth_code);
            }
        }
Example #6
0
        /// <summary>
        /// 获取第三方公众号接口调用凭据
        /// </summary>
        /// <param name="component_access_token"></param>
        /// <param name="authorization_code"></param>
        /// <returns></returns>
        public static Authorization_Info GetAuthorizer_access_token(string component_access_token, string authorization_code)
        {
            var      data     = new { component_appid = AppID, authorization_code = authorization_code };
            string   res      = HttpWebResponseUtility.CreatePostDataResponse("https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=" + component_access_token, JsonConvert.SerializeObject(data));
            ResModel resModel = JsonConvert.DeserializeObject <ResModel>(res);

            if (resModel.errcode.HasValue)
            {
                return(null);
            }
            else
            {
                return(resModel.authorization_info);
            }
        }
Example #7
0
        /// <summary>
        /// 获取接口调用凭据Component_access_token
        /// </summary>
        /// <param name="componentVerifyTicket">推送的ComponentVerifyTicket</param>
        /// <returns></returns>
        public static string GetComponent_access_token(string componentVerifyTicket)
        {
            var    data = new { component_appid = AppID, component_appsecret = AppSecret, component_verify_ticket = componentVerifyTicket };
            string res  = HttpWebResponseUtility.CreatePostDataResponse("https://api.weixin.qq.com/cgi-bin/component/api_component_token", JsonConvert.SerializeObject(data));

            log.Info(res);
            ResModel resModel = JsonConvert.DeserializeObject <ResModel>(res);

            if (resModel.errcode.HasValue)
            {
                return("");
            }
            else
            {
                return(resModel.component_access_token);
            }
        }
Example #8
0
        /// <summary>
        /// 刷新第三方公众号的接口调用凭据
        /// </summary>
        /// <param name="component_access_token">接口调用凭据</param>
        /// <param name="authorizer_refresh_token">第三方公众号的刷新凭据</param>
        /// <param name="authorizer_appid">第三方APPID</param>
        /// <returns></returns>
        public static Authorization_Info Getauthorizer_refresh_token(string component_access_token, string authorizer_refresh_token, string authorizer_appid)
        {
            var    data = new { component_appid = AppID, authorizer_appid = authorizer_appid, authorizer_refresh_token = authorizer_refresh_token };
            string res  = HttpWebResponseUtility.CreatePostDataResponse("https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=" + component_access_token, JsonConvert.SerializeObject(data));

            log.Info(res);
            Authorization_Info authorization_Info = JsonConvert.DeserializeObject <Authorization_Info>(res);

            if (authorization_Info.errcode.HasValue)
            {
                return(null);
            }
            else
            {
                return(authorization_Info);
            }
        }
Example #9
0
        /// <summary>
        /// 发送模板消息
        /// </summary>
        /// <param name="AppID"></param>
        /// <param name="accessToken"></param>
        /// <param name="obj"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static int?sendTemplateMessage(string AppID, string accessToken, object obj)
        {
            BaseModel templateMessageModel = new BaseModel();
            string    res = "";

            try
            {
                res = HttpWebResponseUtility.CreatePostDataResponse(Const.template_message + accessToken, JsonConvert.SerializeObject(obj));
                log.Info(res);
                templateMessageModel = JsonConvert.DeserializeObject <BaseModel>(res);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return(templateMessageModel.msgid);
        }
Example #10
0
        public static string getWeiXinInfo(string appid, string component_access_token)
        {
            var data = new { component_appid = AppID, authorizer_appid = appid };

            return(HttpWebResponseUtility.CreatePostDataResponse("https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=" + component_access_token, JsonConvert.SerializeObject(data)));
        }
Example #11
0
        public static void SendCustomMessage(object message, string accessToken)
        {
            string res = HttpWebResponseUtility.CreatePostDataResponse(Const.custom_message + accessToken, JsonConvert.SerializeObject(message));

            log.Info("发送客服消息返回:" + res);
        }