mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
新增 微信第三方平台 获取预授权码接口
This commit is contained in:
@@ -88,6 +88,27 @@ public class AgentDevController extends BaseController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取预授权码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getPreAuthorizerCode")
|
||||
public RestApiResponse<?> getPreAuthorizerCode() {
|
||||
logger.info("微信第三方平台 获取预授权码 start");
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
String preAuthorizerCode = agentDevService.getPreAuthorizerCode();
|
||||
response = new RestApiResponse<>(preAuthorizerCode);
|
||||
} catch (Exception e) {
|
||||
logger.error("微信第三方平台 获取预授权码 error, ", e);
|
||||
response = new RestApiResponse<>(e);
|
||||
}
|
||||
logger.info("微信第三方平台 获取预授权码 result:{}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 使用授权码获取授权信息
|
||||
*
|
||||
|
||||
@@ -359,6 +359,37 @@ public class AgentDevService {
|
||||
return String.valueOf(auditId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取预授权码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPreAuthorizerCode() {
|
||||
// 获取平台令牌
|
||||
GetComponentTokenDTO dto = GetComponentTokenDTO.builder()
|
||||
.appId(PLATFORM_APP_ID)
|
||||
.appSecret(PLATFORM_APP_SECRET)
|
||||
.verifyTicket(null)
|
||||
.build();
|
||||
String componentToken = getComponentToken(dto);
|
||||
|
||||
// 拼接参数
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=" + componentToken;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("component_appid", PLATFORM_APP_ID);
|
||||
// 发送请求
|
||||
String result = HttpUtils.sendPost(url, JSONObject.toJSONString(jsonObject));
|
||||
logger.info("微信第三方平台 获取预授权码请求 params:{}, result:{}", JSONObject.toJSONString(jsonObject), result);
|
||||
// 将返回结果转成json对象
|
||||
JSONObject resultJson = JSONObject.parseObject(result);
|
||||
String preAuthCode = resultJson.getString("pre_auth_code");
|
||||
if (StringUtils.isBlank(preAuthCode)) {
|
||||
logger.error("微信第三方平台 获取预授权码为空");
|
||||
return null;
|
||||
}
|
||||
return preAuthCode;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
JSONArray array = new JSONArray();
|
||||
|
||||
Reference in New Issue
Block a user