mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 20:49:00 +08:00
Merge branch '微信jssdk' of 202405031425/pigx into dev
This commit is contained in:
commit
daafcd9eea
1 file changed
+34
+34
@@ -3,6 +3,7 @@ package com.pig4cloud.pigx.mp.controller;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pigx.common.api.encrypt.annotation.NoEncrypt;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantBroker;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import com.pig4cloud.pigx.common.xss.core.XssCleanIgnore;
|
||||
@@ -10,11 +11,15 @@ import com.pig4cloud.pigx.mp.config.WxMpContextHolder;
|
||||
import com.pig4cloud.pigx.mp.config.WxMpInitConfigRunner;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Binary Wang
|
||||
* @author lengleng
|
||||
@@ -87,6 +92,35 @@ public class WxPortalController {
|
||||
(id) -> handleMessage(appId, requestBody, signature, timestamp, nonce, openid, encType, msgSignature));
|
||||
}
|
||||
|
||||
@XssCleanIgnore
|
||||
@GetMapping("/jssdk-config")
|
||||
public R getJssdkConfig(@PathVariable("appId") String appId,
|
||||
@RequestParam(name = "url", required = false) String url){
|
||||
if (StrUtil.isAllBlank(url)) {
|
||||
throw new IllegalArgumentException("请求参数非法,请核实!");
|
||||
}
|
||||
|
||||
final WxMpService wxService = WxMpInitConfigRunner.getMpServices().get(appId);
|
||||
|
||||
if (wxService == null) {
|
||||
throw new IllegalArgumentException(String.format("未找到对应appid=[%d]的配置,请核实!", appId));
|
||||
}
|
||||
|
||||
try {
|
||||
WxJsapiSignature signature = wxService.createJsapiSignature(url);
|
||||
|
||||
return R.ok(Map.of(
|
||||
"appId", signature.getAppId(),
|
||||
"timestamp", signature.getTimestamp(),
|
||||
"nonceStr", signature.getNonceStr(),
|
||||
"signature", signature.getSignature()
|
||||
));
|
||||
} catch (WxErrorException e) {
|
||||
log.error("获取微信js api出现错误: {}", e.getLocalizedMessage());
|
||||
return R.failed("获取微信js api出现错误: " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信消息处理
|
||||
* @param appId 多公众号标志位
|
||||
|
||||
Reference in new issue
Block a user