|
|
@@ -4,9 +4,12 @@ import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fs.app.facade.CallbackProcessingFacadeService;
|
|
|
import com.fs.common.constant.SystemConstant;
|
|
|
import com.fs.common.result.Result;
|
|
|
+import com.fs.newAdv.domain.AdvMiniConfig;
|
|
|
+import com.fs.newAdv.service.IAdvMiniConfigService;
|
|
|
import com.fs.wx.miniapp.config.WxMaProperties;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -15,7 +18,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
@@ -34,34 +39,49 @@ public class WeChatController {
|
|
|
@Autowired
|
|
|
private WxMaProperties properties;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IAdvMiniConfigService advMiniConfigService;
|
|
|
+
|
|
|
@GetMapping("/getSchemeUrl")
|
|
|
public Result<String> getSchemeUrl(@RequestParam(value = "traceId") String traceId) {
|
|
|
- String appId = "wx0447a16ef6199f03";
|
|
|
- String secret = "f063fcd818e31d4c89013a67f5123990";
|
|
|
- HttpResponse execute2 = HttpRequest.get("https://api.weixin.qq.com/cgi-bin/token")
|
|
|
- .form("grant_type", "client_credential")
|
|
|
- .form("appid", appId)
|
|
|
- .form("secret", secret)
|
|
|
- .timeout(SystemConstant.API_TIMEOUT)
|
|
|
- .execute();
|
|
|
- JSONObject obj = JSONObject.parseObject(execute2.body());
|
|
|
- String access_token = obj.getString("access_token");
|
|
|
-
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- Map<String, Object> map2 = new HashMap<>();
|
|
|
- map2.put("path", "/pages/shopping/productDetails");
|
|
|
- map2.put("query", "traceId=" + traceId);
|
|
|
- //map2.put("env_version", "trial");
|
|
|
- map.put("jump_wxa", map2);
|
|
|
- map.put("is_expire", false);
|
|
|
- HttpResponse execute = HttpRequest.post("https://api.weixin.qq.com/wxa/generatescheme?access_token=" + access_token)
|
|
|
- .header("Content-Type", "application/json")
|
|
|
- .body(JSONUtil.toJsonStr(map))
|
|
|
- .timeout(SystemConstant.API_TIMEOUT)
|
|
|
- .execute();
|
|
|
- log.info("getSchemeUrl:{}", execute.body());
|
|
|
- obj = JSONObject.parseObject(execute.body());
|
|
|
- //response.addHeader("Access-Control-Allow-Origin", "*");
|
|
|
- return Result.success(obj.getString("openlink"));
|
|
|
+ List<AdvMiniConfig> list = advMiniConfigService.list(new LambdaQueryWrapper<AdvMiniConfig>()
|
|
|
+ .eq(AdvMiniConfig::getStatus, 1));
|
|
|
+ for (AdvMiniConfig advMiniConfig : list) {
|
|
|
+ try {
|
|
|
+ String access_token = advMiniConfig.getAccessToken();
|
|
|
+ // 判断token是否过期
|
|
|
+ if (advMiniConfig.getExpiresIn().isBefore(LocalDateTime.now().plusMinutes(10))) {
|
|
|
+ HttpResponse execute2 = HttpRequest.get("https://api.weixin.qq.com/cgi-bin/token")
|
|
|
+ .form("grant_type", "client_credential")
|
|
|
+ .form("appid", advMiniConfig.getAppId())
|
|
|
+ .form("secret", advMiniConfig.getAppSecret())
|
|
|
+ .timeout(SystemConstant.API_TIMEOUT)
|
|
|
+ .execute();
|
|
|
+ JSONObject obj = JSONObject.parseObject(execute2.body());
|
|
|
+ access_token = obj.getString("access_token");
|
|
|
+ advMiniConfig.setAccessToken(access_token);
|
|
|
+ advMiniConfigService.updateById(advMiniConfig);
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ Map<String, Object> map2 = new HashMap<>();
|
|
|
+ map2.put("path", "pages/home/productList");
|
|
|
+ map2.put("query", "traceId=" + traceId);
|
|
|
+ map2.put("env_version", "trial");
|
|
|
+ map.put("jump_wxa", map2);
|
|
|
+ map.put("is_expire", false);
|
|
|
+ HttpResponse execute = HttpRequest.post("https://api.weixin.qq.com/wxa/generatescheme?access_token=" + access_token)
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .body(JSONUtil.toJsonStr(map))
|
|
|
+ .timeout(SystemConstant.API_TIMEOUT)
|
|
|
+ .execute();
|
|
|
+ log.info("getSchemeUrl:{}", execute.body());
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(execute.body());
|
|
|
+ //response.addHeader("Access-Control-Allow-Origin", "*");
|
|
|
+ return Result.success(jsonObject.getString("openlink"));
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("getSchemeUrl error:{}",advMiniConfig.getAppId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.success("");
|
|
|
}
|
|
|
}
|