示例#1
0
        internal static void SendCustomerMessage(string accessToken, CustomerJsonMessage msg)
        {
            var    json = msg.GetJson();
            string url  = string.Format("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}", accessToken);

            Log.Debug("\r\n发送客服消息 json 数据:>>\r\n{0}", json);
            var result = HttpRequestHelper.PostHttp_ForamtByJson(url, json);

            Log.Debug("\r\n发送客服消息 json 返回值:>>\r\n{0}", result);
            var returnCode = GlobalReturnCode.GetReturnCode(json);

            if (!returnCode.IsRequestSuccess)
            {
                throw new WeixinRequestApiException(string.Format("获取 access_token 失败\r\n全局返回值:{0}\r\n对应说明:{1}\r\nJson:{2}\r\n请求路径:{3}", returnCode.ErrCode, returnCode.Msg, returnCode.Json, url), returnCode);
            }
        }
示例#2
0
        private static Dictionary <string, object> GetAccessTokenDic(string appId, string _AppSecret)
        {
            var url  = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appId, _AppSecret);
            var json = HttpRequestHelper.GetHttp_ForamtByJson(url);

            Log.Debug("\r\n获取 access_token json返回值:>>\r\n{0}", json);
            var returnCode = GlobalReturnCode.GetReturnCode(json);

            if (!returnCode.IsRequestSuccess)
            {
                throw new WeixinRequestApiException(string.Format("获取 access_token 失败\r\n全局返回值:{0}\r\n对应说明:{1}\r\nJson:{2}\r\n请求路径:{3}", returnCode.ErrCode, returnCode.Msg, returnCode.Json, url), returnCode);
            }
            var jsonObj = JsonSerializerHelper.Deserialize(json);

            return(jsonObj);
        }
示例#3
0
        internal static OAuth2AccessToken GetOAuthAccessToken(string code, string appId, string appSecret)
        {
            var url  = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appId, appSecret, code);
            var json = HttpRequestHelper.GetHttp_ForamtByJson(url);

            Log.Debug("\r\n获取 OAuth2.0 access_token json返回值:>>\r\n{0}", json);
            var returnCode = GlobalReturnCode.GetReturnCode(json);

            if (!returnCode.IsRequestSuccess)
            {
                throw new WeixinRequestApiException(string.Format("获取 OAuth2.0 access_token 失败\r\n全局返回值:{0}\r\n对应说明:{1}\r\nJson:{2}\r\n请求路径:{3}", returnCode.ErrCode, returnCode.Msg, returnCode.Json, url), returnCode);
            }
            var oAuth2AccessToken = JsonSerializerHelper.ConvertJsonStringToObjectByJsonPropertyAttribute <OAuth2AccessToken>(json);

            return(oAuth2AccessToken);
        }
示例#4
0
        internal static OAuth2UserInfo GetUserInfo(string openId, string oAuthAccessToken)
        {
            var url  = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", oAuthAccessToken, openId);
            var json = HttpRequestHelper.GetHttp_ForamtByJson(url);

            Log.Debug("\r\n获取用户信息 json返回值:>>\r\n{0}", json);
            var returnCode = GlobalReturnCode.GetReturnCode(json);

            if (!returnCode.IsRequestSuccess)
            {
                throw new WeixinRequestApiException(string.Format("获取用户信息失败\r\n全局返回值:{0}\r\n对应说明:{1}\r\nJson:{2}\r\n请求路径:{3}", returnCode.ErrCode, returnCode.Msg, returnCode.Json, url), returnCode);
            }
            var userInfo = JsonSerializerHelper.ConvertJsonStringToObjectByJsonPropertyAttribute <OAuth2UserInfo>(json);

            return(userInfo);
        }
示例#5
0
        private static QRCodeInfo CreateQR(object obj, string accessToken)
        {
            var url  = string.Format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}", accessToken);
            var json = JsonSerializerHelper.Serialize(obj);

            Log.Debug("\r\n创建参数二维码 json数据:>>\r\n{0}", json);
            var resultJson = HttpRequestHelper.PostHttp_ForamtByJson(url, json);

            Log.Debug("\r\n创建参数二维码 json返回值:>>\r\n{0}", resultJson);
            var returnCode = GlobalReturnCode.GetReturnCode(resultJson);

            if (!returnCode.IsRequestSuccess)
            {
                throw new WeixinRequestApiException(string.Format("创建二维码失败\r\n全局返回值:{0}\r\n对应说明:{1}\r\nJson:{2}\r\n请求路径:{3}", returnCode.ErrCode, returnCode.Msg, returnCode.Json, url), returnCode);
            }
            var qrCodeInfo = JsonSerializerHelper.ConvertJsonStringToObjectByJsonPropertyAttribute <QRCodeInfo>(resultJson);

            qrCodeInfo.ImgUrl = string.Format("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={0}", HttpUtility.UrlEncode(qrCodeInfo.Ticket));
            return(qrCodeInfo);
        }