mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-05-10 01:08:21 +08:00
增加微信jsConfig
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.mdd.front.controller;
|
||||
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.front.service.IWechatService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/wechat")
|
||||
@Api(tags = "微信管理")
|
||||
public class WechatController {
|
||||
|
||||
@Resource
|
||||
IWechatService iWechatService;
|
||||
|
||||
@NotLogin
|
||||
@GetMapping("/jsConfig")
|
||||
@ApiOperation("微信jsConfig")
|
||||
public AjaxResult<Object> jsConfig(@Validated @NotEmpty() @RequestParam("url") String url) throws Exception {
|
||||
Map<String, Object> map = iWechatService.jsConfig(url);
|
||||
return AjaxResult.success(map);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mdd.front.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IWechatService {
|
||||
|
||||
Map<String, Object> jsConfig(String url) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.mdd.front.service.impl;
|
||||
|
||||
import com.mdd.common.plugin.wechat.WxMnpDriver;
|
||||
import com.mdd.common.util.ConfigUtils;
|
||||
import com.mdd.front.service.IWechatService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class WechatServiceImpl implements IWechatService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> jsConfig(String url) throws Exception {
|
||||
String appId = ConfigUtils.get("oa_channel", "appId");
|
||||
String accessToken = WxMnpDriver.mnp().getAccessToken();
|
||||
String jsapiTicket = WxMnpDriver.getJsSdkGetTicket(accessToken);
|
||||
String timestamp = Long.toString(System.currentTimeMillis() / 1000);
|
||||
String nonceStr = UUID.randomUUID().toString();
|
||||
String signature = WxMnpDriver.buildJSSDKSignature(jsapiTicket,timestamp,nonceStr,url);
|
||||
|
||||
List<String> array = Arrays.asList(
|
||||
"onMenuShareTimeline",
|
||||
"onMenuShareAppMessage",
|
||||
"onMenuShareQQ",
|
||||
"onMenuShareWeibo",
|
||||
"onMenuShareQZone",
|
||||
"openLocation",
|
||||
"getLocation",
|
||||
"chooseWXPay",
|
||||
"updateAppMessageShareData",
|
||||
"updateTimelineShareData",
|
||||
"openAddress",
|
||||
"scanQRCode");
|
||||
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("url", url);
|
||||
map.put("jsapi_ticket", jsapiTicket);
|
||||
map.put("nonceStr", nonceStr);
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("signature", signature);
|
||||
map.put("appid", appId);
|
||||
map.put("jsApiList", array);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user