当前位置:网站首页>微信小程序接口调用凭证(获取token)auth.getAccessToken接口开发
微信小程序接口调用凭证(获取token)auth.getAccessToken接口开发
2022-08-01 05:09:00 【市井榴芒】
1、接口规范
小程序接口调用凭证auth.getAccessToken接口规范参考链接
1.1、接口请求地址
GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
1.2、接口请求参数
appid:小程序 appIdsecret:小程序 appSecretgrant_type:授权类型,填写 client_credential
1.3、接口响应参数(返回的 JSON 数据包)
access_token:获取到的凭证expires_in:凭证有效时间,单位:秒。目前是7200秒之内的值。errcode:错误码***(异常情况才会有错误码返回,正常是没有该字段返回的)***errmsg:错误信息
2、准备工作
需要准备请求接口的2个参数:appid:小程序 appId,需要小程序注册申请流程获得;secret:小程序 appSecret,需要在小程序开发配置选项里面经由管理员扫码授权生成;
3、代码
//getWxAccessToken()方法用来将所有请求参数拼接起来形成最终的请求URL,可以在postman/apifox里面先行测通
//APP_ID=小程序 appId
//APP_SECRET=小程序 appSecret
String urlAccessToken = getWxAccessToken(APP_ID, APP_SECRET);
//发起请求
String respAccessToken = HttpUtil.get(urlAccessToken);
if(StringUtil.isNull(respAccessToken)){
throw new ServiceException("803","请求access_token失败");
}
//将响应转为Json对象
JSONObject respAccessTokenObj = JSONObject.parseObject(respAccessToken);
//获取accessToken
String accessToken = respAccessTokenObj.getString("access_token");
if(accessToken==null){
throw new ServiceException("804","获取access_token失败");
}
边栏推荐
- Selenium:简介
- LeetCode 387. 字符串中的第一个唯一字符
- Selenium: element positioning
- 2022/07/29 入职健海JustFE团队,我学到了高效开发(年中总结)
- (2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)
- [MySQL] 多表查询
- ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
- PaddleX部署推理模型和GUI界面测试结果不一致的解决方法
- (Codeforce 757)E. Bash Plays with Functions(积性函数)
- 状态压缩dp
猜你喜欢

MySQL-数据操作-分组查询-连接查询-子查询-分页查询-联合查询

2022/07/29 入职健海JustFE团队,我学到了高效开发(年中总结)

MySQL-Data Operation-Group Query-Join Query-Subquery-Pagination Query-Joint Query

USB3.0:VL817Q7-C0的LAYOUT指南(二)

Optional parameters typescript19 - object

mysql中解决存储过程表名通过变量传递的方法

(2022牛客多校四)N-Particle Arts(思维)

Excel record of integer programming optimization model to solve the problem

2022年湖南工学院ACM集训第六次周测题解

关于给Qt做一个软件初始化的进度条
随机推荐
PAT class B 1001 (3n+1) conjecture
可持久化线段树
2022/07/29 入职健海JustFE团队,我学到了高效开发(年中总结)
typescript28 - value of enumeration type and data enumeration
typescript23-元组
7月编程排行榜来啦!这次有何新变化?
请问shake数据库中想把源的db0的数据同步到目的db5,参数怎么设置呢?
Excel做题记录——整数规划优化模型
NDK does not contain any platforms问题解决
MySQL-数据操作-分组查询-连接查询-子查询-分页查询-联合查询
[MySQL] 多表查询
typescript24-类型推论
初识shell脚本
Power button (LeetCode) 212. The word search II (2022.07.31)
MySQL-数据定义语言-DDLdatebase define language
Selenium: Element wait
JWL-11/2-99.9A电流继电器
[target detection] YOLOv7 theoretical introduction + practical test
typescript26-字面量类型
备战金九银十,如何顺利通过互联网大厂Android的笔面试?