Exemplo n.º 1
0
        //post方法调用接口获取pre_auth_code
        public string GetPre_Auth_Code(string appid, string token)
        {
            var obj = new
            {
                component_appid = appid
            };
            string responseStr =
                WebService.PostFunction("https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=" + token, obj);

            CommonMethod.Pre_Auth_Code pacModel = CommonMethod.JsonHelper.ParseFromJson <CommonMethod.Pre_Auth_Code>(responseStr);
            if (pacModel != null && !string.IsNullOrEmpty(pacModel.pre_auth_code))
            {
                return(pacModel.pre_auth_code);
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 2
0
        //post方法调用接口获取“授权公众号”详细信息
        public static CommonMethod.RootObjectDetail GetAuthInfo(string appid, string authAppid, string componentToken)
        {
            var obj = new
            {
                component_appid  = appid,
                authorizer_appid = authAppid
            };
            string responseStr =
                WebService.PostFunction("https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=" + componentToken, obj);

            CommonMethod.RootObjectDetail authInfo = CommonMethod.JsonHelper.ParseFromJson <CommonMethod.RootObjectDetail>(responseStr);
            if (authInfo != null)
            {
                return(authInfo);
            }
            else
            {
                return(new CommonMethod.RootObjectDetail());
            }
        }
Exemplo n.º 3
0
        //post方法调用接口获取token
        public CommonMethod.RootObject GetAuthToken(string appid, string authCode, string componentToken)
        {
            var obj = new
            {
                component_appid    = appid,
                authorization_code = authCode
            };
            string responseStr =
                WebService.PostFunction("https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=" + componentToken, obj);

            CommonMethod.RootObject authInfoModel = CommonMethod.JsonHelper.ParseFromJson <CommonMethod.RootObject>(responseStr);
            //CommonMethod.RootObject rb = JsonConvert.DeserializeObject<CommonMethod.RootObject>(responseStr);//这种方法也可以解析
            if (authInfoModel != null)
            {
                return(authInfoModel);
            }
            else
            {
                return(new CommonMethod.RootObject());
            }
        }
Exemplo n.º 4
0
        //post方法调用接口获取token
        public static string GetToken(string appid, string secret, string ticket)
        {
            var obj = new
            {
                component_appid         = appid,
                component_appsecret     = secret,
                component_verify_ticket = ticket
            };
            string responseStr =
                WebService.PostFunction("https://api.weixin.qq.com/cgi-bin/component/api_component_token", obj);

            CommonMethod.Token tokenModel = CommonMethod.JsonHelper.ParseFromJson <CommonMethod.Token>(responseStr);
            if (tokenModel != null && !string.IsNullOrEmpty(tokenModel.component_access_token))
            {
                return(tokenModel.component_access_token);
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// post方法调用接口 重新获取token
        /// </summary>
        /// <param name="appid">第三方平台appid</param>
        /// <param name="authAppid">授权方appid</param>
        /// <param name="refreshToken">刷新token</param>
        /// <param name="componentToken">第三方平台token</param>
        /// <returns></returns>
        public static CommonMethod.RefreshToken RefreshToken(string appid, string authAppid, string refreshToken, string componentToken)
        {
            var obj = new
            {
                component_appid          = appid,
                authorizer_appid         = authAppid,
                authorizer_refresh_token = refreshToken
            };
            string responseStr =
                WebService.PostFunction("https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=" + componentToken, obj);

            CommonMethod.RefreshToken rToken = CommonMethod.JsonHelper.ParseFromJson <CommonMethod.RefreshToken>(responseStr);
            //CommonMethod.RootObject rb = JsonConvert.DeserializeObject<CommonMethod.RootObject>(responseStr);//这种方法也可以解析
            if (rToken != null)
            {
                return(rToken);
            }
            else
            {
                return(new CommonMethod.RefreshToken());
            }
        }