码迷,mamicode.com
首页 > 微信 > 详细

微信公众账号登陆授权开发——4

时间:2015-08-27 13:37:24      阅读:375      评论:0      收藏:0      [点我收藏+]

标签:开放平台   微信   

获取预授权码

获取到access_token后就可以获取pre_auth_code预授权码了

-------------------------------------------------------------------------官方文档说明开始-----------------------------------------------------------------------------------


2、获取预授权码

该API用于获取预授权码。预授权码用于公众号授权时的第三方平台方安全验证。

接口调用请求说明

http请求方式: POST(请使用https协议)

https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=xxx

POST数据示例:

{
"component_appid":"appid_value" 
}
   

请求参数说明
参数 说明
component_appid 第三方平台方appid
返回结果示例

{
"pre_auth_code":"Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw",
"expires_in":600
}
   

结果参数说明
参数 说明
pre_auth_code 预授权码
expires_in 有效期,为20分钟

----------------------------------------------------官方文档说明结束--------------------------------------------------------------------------------

/**
     * 2、获取预授权码
     * 
     * http请求方式: POST(请使用https协议)
     * 
     * https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?
     * component_access_token=xxx
     * 
     * POST数据示例: { "component_appid":"appid_value" }
     */
    public static String getPre_auth_code() {
        String url = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=" + getToken();
        Pre_auth_code pre = new Pre_auth_code();
        pre.setComponent_appid("*****");
        JSONObject jsonObject = WeixinUtil.httpRequest(url, "POST", JSONObject.fromObject(pre).toString());
        System.out.println("获取的预授权码为:  " + jsonObject.toString());
        return jsonObject.getString("pre_auth_code");
    }

将获取预授权码的参数封装成为一个bean

/**
 * 2、获取预授权码
 * 
 * 该API用于获取预授权码。预授权码用于公众号授权时的第三方平台方安全验证。
 * 
 * @author YangChao
 * 
 */
public class Pre_auth_code {

    // 第三方平台方appid
    private String component_appid;

    public String getComponent_appid() {
        return component_appid;
    }

    public void setComponent_appid(String component_appid) {
        this.component_appid = component_appid;
    }

}




版权声明:本文为博主原创文章,未经博主允许不得转载。

微信公众账号登陆授权开发——4

标签:开放平台   微信   

原文地址:http://blog.csdn.net/yangchao13341408947/article/details/48023941

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!