微信公众帐号登录受权开发——4

获取预受权码

获取到access_token后就能够获取pre_auth_code预受权码了

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

java


二、获取预受权码

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

接口调用请求说明

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

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

POST数据示例:app

{
"component_appid":"appid_value" 
}
   this

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

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

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

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

/**
     * 二、获取预受权码
     * 
     * 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

/**
 * 二、获取预受权码
 * 
 * 该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;
    }

}




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

相关文章
相关标签/搜索