Example #1
0
        public ResultModel <LoginSessionModel> Getjscode2session(string code)
        {
            var url = string.Format(SprogramConfig.jscode2session, BasicConfig.Sprogram_AppId, BasicConfig.SprogramAppSecret, code);

            var jsonResult = WHttpUtil.Get(url, "");

            if (!string.IsNullOrWhiteSpace(jsonResult))
            {
                var result = JsonConvert.DeserializeObject <LoginSessionModel>(jsonResult);

                if (result == null)
                {
                    return(new ResultModel <LoginSessionModel>
                    {
                        code = 0,
                        msg = jsonResult,
                        data = null
                    });
                }

                return(new ResultModel <LoginSessionModel>
                {
                    code = 1,
                    msg = jsonResult,
                    data = result
                });
            }

            return(null);
        }
Example #2
0
        public ResultModel <AccessTokenModel> GetAccessTokenData(string code)
        {
            var url = string.Format(WrapConfig.AccessTokenUrl, BasicConfig.WeChat_AppId, BasicConfig.WeChat_Secret, code);

            var jsonResult = WHttpUtil.Get(url);

            if (!string.IsNullOrWhiteSpace(jsonResult))
            {
                var result = JsonConvert.DeserializeObject <AccessTokenModel>(jsonResult);

                if (result == null)
                {
                    return(new ResultModel <AccessTokenModel>
                    {
                        code = 0,
                        msg = jsonResult,
                        data = null
                    });
                }

                return(new ResultModel <AccessTokenModel>
                {
                    code = 1,
                    msg = jsonResult,
                    data = result
                });
            }

            return(null);
        }
 public ResultModel <WechatStatusModel> CreateMenu(string appid, string appsecret, string menuhtml)
 {
     try
     {
         AuthorService author = new AuthorService();
         var           token  = author.GetBaseAccessTokenData();
         if (token != null && token.code == 1 && !string.IsNullOrWhiteSpace(token.data.access_token))
         {
             string createurl  = string.Format(WrapConfig.MenuCreate, token.data.access_token);
             var    jsonresult = WHttpUtil.Get(createurl, menuhtml);
             var    err        = JsonConvert.DeserializeObject <ErroResult>(jsonresult);
             if (err.errmsg == "ok")
             {
                 return(new ResultModel <WechatStatusModel>
                 {
                     code = 1,
                     msg = "绑定微信目录成功",
                     data = new WechatStatusModel()
                     {
                         msg = err.errmsg,
                         status = true
                     }
                 });
             }
             else
             {
                 return(new ResultModel <WechatStatusModel>
                 {
                     code = 0,
                     msg = "绑定微信目录失败",
                     data = new WechatStatusModel()
                     {
                         msg = "错误代码:" + err.errcode + "," + err.errmsg,
                         status = false
                     }
                 });
             }
         }
         else
         {
             return(new ResultModel <WechatStatusModel>
             {
                 code = 0,
                 msg = "token获取为空",
                 data = null
             });
         }
     }
     catch (Exception e)
     {
         Log.Err(e, "CreateMenu创建菜单异常");
         return(new ResultModel <WechatStatusModel>
         {
             code = 0,
             msg = e.Message,
             data = null
         });
     }
 }