微信开发平台---一键授权

本文介绍了微信开发平台中实现一键授权的步骤,包括如何获取登录令牌和预授权码,详细说明了授权过程的关键路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

哪个微信开发文档传送什么参数我就不写

第一步拿到开放平台的登录令牌


public static  String loginToken(EssentialInfo essentialInfo){
     net.sf.json.JSONObject accessTokenRequest =new net.sf.json.JSONObject();//第三方平台临时令牌请求
    accessTokenRequest.put("component_appid",Configure.getValue("AppID"));
    accessTokenRequest.put("component_appsecret",Configure.getValue("AppSecret"));
    accessTokenRequest.put("component_verify_ticket",essentialInfo.getRemark());
     net.sf.json.JSONObject accessTokenCallback= WxstoreUtils.httpRequest("https://api.weixin.qq.com/cgi-bin/component/api_component_token","POST",accessTokenRequest.toString());
    // JSONArray js=bs.getJSONArray("component_access_token");
     String accessToken=accessTokenCallback.getString("component_access_token");//accessTokenCallback  第三方平台临时令牌请求回调
     return accessToken;
 }

第二步 获取预授权码

/**
 * 获取扫描公众号的路径
 * @return
 */
public static String authorized( EssentialInfo essentialInfo){
    String accessToken= loginToken(essentialInfo);
    net.sf.json.JSONObject preAuthRequest=new net.sf.json.JSONObject();//preAuthRequest  预授权请求
    preAuthRequest.put("component_appid",Configure.getValue("AppID"));
    preAuthRequest.put("component_appsecret", Configure.getValue("AppSecret"));
    net.sf.json.JSONObject preAuthCallback= WxstoreUtils.httpRequest("https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token="+accessToken,"POST",preAuthRequest.toString());
    Map<String,Object> preAuthMap=(Map<String,Object>)preAuthCallback;//preAuthMap  预授权转换map
    String preAuthCode=(String)preAuthMap.get("pre_auth_code");//预授权码
    String authorizationPath="https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid="+Configure.getValue("AppID")+"&pre_auth_code="+preAuthCode+"&redirect_uri=" +
            Configure.getValue("MAEAURL");//authorizationPath  授权路径
    return authorizationPath;
}

authorizationPath  这就是具体要跳转的路径  你想怎么跳都行;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值