zoukankan      html  css  js  c++  java
  • 微信公众账号登陆授权开发——4

    获取预授权码

    获取到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;
        }
    
    }
    




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

  • 相关阅读:
    记php多张图片合成一张图片 压缩固定分辨率 合并生成竖列 纵向长图(可用于商品详情图合并下载)
    记php-mysql分页查询出现重复数据
    记laravel order by 问题
    记登录注册时候 前端js明文密码 加密传输 php解密
    记下载oss图片接口(附带删除)
    记tp5.1使用composer PhpOffice的xlsx表格文件导入数据库
    记php移动并压缩多级目录文件为zip文件并上传oss
    Jmeter服务器性能监控工具插件之ServerAgent
    Jmeter阶梯式加压测试
    Jmeter 下载+安装+汉化+版本更新+备份使用(Jmeter 4+版本均适用)
  • 原文地址:https://www.cnblogs.com/blogs-chao/p/4764887.html
Copyright © 2011-2022 走看看