|
@@ -1,11 +1,8 @@
|
|
|
package com.caimei365.wechat.controller;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.wechat.utils.HttpUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -24,11 +21,6 @@ public class WechatDebugApi {
|
|
|
@Value("${wechat.apiUrl}")
|
|
|
private String wechatApiUrl;
|
|
|
|
|
|
- @Value("${wechat.caimei.appid}")
|
|
|
- private String caimeiAppid;
|
|
|
- @Value("${wechat.caimei.secret}")
|
|
|
- private String caimeiSecret;
|
|
|
-
|
|
|
/**
|
|
|
* 获取微信 access_token
|
|
|
*/
|
|
@@ -45,38 +37,23 @@ public class WechatDebugApi {
|
|
|
* @param openid 初始openid,不填默认从头开始拉取
|
|
|
*/
|
|
|
@GetMapping("/wechat/debug/user/list")
|
|
|
- public String getUserList(String appid, String secret, String openid) {
|
|
|
- String tokenUrl = wechatApiUrl + "/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret;
|
|
|
- String jsonResult = HttpUtil.httpRequest(tokenUrl, "GET", null);
|
|
|
- log.info("【微信接口调试】获取access_token:{}", jsonResult);
|
|
|
- if(StringUtils.hasLength(jsonResult)){
|
|
|
- JSONObject jsonObject = JSON.parseObject(jsonResult);
|
|
|
- String accessToken = jsonObject.getString("access_token");
|
|
|
- String userUrl = wechatApiUrl + "/cgi-bin/user/get?access_token="+ accessToken + "&next_openid="+ openid;
|
|
|
- String result = HttpUtil.httpRequest(userUrl, "GET", null);
|
|
|
- log.info("【微信接口调试】获取用户列表:{}", result);
|
|
|
- return result;
|
|
|
- }
|
|
|
- return "获取微信用户列表异常";
|
|
|
+ public String getUserList(String token, String openid) {
|
|
|
+ String url =wechatApiUrl + "/cgi-bin/user/get?access_token="+ token + "&next_openid="+ openid;
|
|
|
+ String result = HttpUtil.httpRequest(url, "GET", null);
|
|
|
+ log.info("【微信接口调试】获取用户列表:{}", result);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 公众号迁移后更新OpenId
|
|
|
* 帐号迁移15天后,该转换接口将会失效、无法拉取到数据
|
|
|
+ * https://api.weixin.qq.com/cgi-bin/changeopenid?access_token=
|
|
|
*/
|
|
|
@PostMapping("/wechat/debug/change/openid")
|
|
|
- public String changeOpenId(@RequestBody String json) {
|
|
|
- String tokenUrl = wechatApiUrl + "/cgi-bin/token?grant_type=client_credential&appid=" + caimeiAppid + "&secret=" + caimeiSecret;
|
|
|
- String jsonResult = HttpUtil.httpRequest(tokenUrl, "GET", null);
|
|
|
- log.info("【微信接口调试】获取access_token:{}", jsonResult);
|
|
|
- if(StringUtils.hasLength(jsonResult)){
|
|
|
- JSONObject jsonObject = JSON.parseObject(jsonResult);
|
|
|
- String accessToken = jsonObject.getString("access_token");
|
|
|
- String changeUrl = wechatApiUrl + "/cgi-bin/changeopenid?access_token=?access_token="+ accessToken;
|
|
|
- String result = HttpUtil.httpRequest(changeUrl, "POST", json);
|
|
|
- log.info("【微信接口调试】公众号迁移后更新OpenId:{}", result);
|
|
|
- return result;
|
|
|
- }
|
|
|
- return "公众号迁移后更新OpenId异常";
|
|
|
+ public String changeOpenId(@RequestBody String json, String token) {
|
|
|
+ String url = wechatApiUrl + "/cgi-bin/changeopenid?access_token="+ token;
|
|
|
+ String result = HttpUtil.httpRequest(url, "POST", json);
|
|
|
+ log.info("【微信接口调试】公众号迁移后更新OpenId:{}", result);
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|