|
@@ -1,9 +1,10 @@
|
|
|
package net.mingsoft.tf.wx;
|
|
package net.mingsoft.tf.wx;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.codec.Base64;
|
|
|
import cn.hutool.core.map.CaseInsensitiveMap;
|
|
import cn.hutool.core.map.CaseInsensitiveMap;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.http.HttpUtil;
|
|
|
|
|
|
|
+import cn.hutool.http.*;
|
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
@@ -113,6 +114,37 @@ public class WxPeopleAction extends BaseAction {
|
|
|
.orElseGet(ResultData.build()::error);
|
|
.orElseGet(ResultData.build()::error);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Operation(summary = "微信-分享码")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "scene", description = "参数", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "page", description = "页面", in = ParameterIn.QUERY)
|
|
|
|
|
+ })
|
|
|
|
|
+ @GetMapping(value = "/shareCode")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData shareCode(String scene, String page) {
|
|
|
|
|
+ return getWxToken(appid, secret)
|
|
|
|
|
+ .map(token -> {
|
|
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
|
|
+ param.set("scene", scene);
|
|
|
|
|
+ param.set("page", page);
|
|
|
|
|
+ try (HttpResponse response = HttpUtil.createPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + token)
|
|
|
|
|
+ .body(param.toString())
|
|
|
|
|
+ .timeout(HttpGlobalConfig.getTimeout())
|
|
|
|
|
+ .execute()) {
|
|
|
|
|
+ if (StrUtil.containsIgnoreCase(response.header(Header.CONTENT_TYPE), ContentType.JSON.getValue())) {
|
|
|
|
|
+ // 结果是json,代表错误
|
|
|
|
|
+ return ResultData.build().error(new JSONObject(response.body()).getStr("errmsg"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 结果非json,代表成功
|
|
|
|
|
+ return ResultData.build().success(Base64.encode(response.bodyBytes()));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception ignored) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .orElseGet(ResultData.build()::error);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private synchronized static Optional<String> getWxToken(String appid, String secret) {
|
|
private synchronized static Optional<String> getWxToken(String appid, String secret) {
|
|
|
if (wxTokenExpiresIn == null || wxTokenExpiresIn <= System.currentTimeMillis()) {
|
|
if (wxTokenExpiresIn == null || wxTokenExpiresIn <= System.currentTimeMillis()) {
|
|
|
return Optional.of("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret)
|
|
return Optional.of("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret)
|
|
@@ -142,7 +174,7 @@ public class WxPeopleAction extends BaseAction {
|
|
|
@PostMapping(value = "/guest")
|
|
@PostMapping(value = "/guest")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public ResultData guest(@RequestBody GuestRequest guest) {
|
|
public ResultData guest(@RequestBody GuestRequest guest) {
|
|
|
- guestBiz.updateGuest(guest.getOpenid(), guest.getIcon(), guest.getNickName(), guest.getCode(),guest.getExhibitor());
|
|
|
|
|
|
|
+ guestBiz.updateGuest(guest.getOpenid(), guest.getIcon(), guest.getNickName(), guest.getCode(), guest.getExhibitor());
|
|
|
return ResultData.build().success();
|
|
return ResultData.build().success();
|
|
|
}
|
|
}
|
|
|
|
|
|