Commit 09b46378 by xinlaa

Merge branch 'master' of https://gitee.com/LinkWeChat/link-wechat into master

2 parents f483dc11 e6c0eaac
......@@ -7,10 +7,7 @@ import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.service.IWeChatCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* 聊天工具 侧边栏栏 素材收藏
......@@ -31,8 +28,8 @@ public class WeChatCollectionController extends BaseController {
*/
@PreAuthorize("@ss.hasPermi('chat:collection:add')")
@Log(title = "添加收藏", businessType = BusinessType.INSERT)
@PutMapping
public AjaxResult addCollection(@RequestParam(value = "materialId") Long materialId,@RequestParam(value = "userId") Long userId) {
@PostMapping
public AjaxResult addCollection(@RequestParam(value = "materialId") Long materialId, @RequestParam(value = "userId") Long userId) {
return toAjax(weChatCollectionService.addCollection(materialId, userId));
}
......@@ -43,7 +40,7 @@ public class WeChatCollectionController extends BaseController {
@PreAuthorize("@ss.hasPermi('chat:collection:delete')")
@Log(title = "取消收藏", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult cancleCollection(@RequestParam(value = "materialId") Long materialId,@RequestParam(value = "userId") Long userId) {
public AjaxResult cancleCollection(@RequestParam(value = "materialId") Long materialId, @RequestParam(value = "userId") Long userId) {
return toAjax(weChatCollectionService.cancleCollection(materialId, userId));
}
......
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.wecom.TicketUtils;
import com.linkwechat.wecom.client.WeTicketClient;
import com.linkwechat.wecom.domain.WeH5TicketDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.TimeUnit;
/**
* @author danmo
* @description h5 ticket校验接口
* @date 2021/1/6 11:23
**/
@Slf4j
@RequestMapping(value = "/wecom/ticket/")
@RestController
public class WeTicketController extends BaseController {
@Autowired
private RedisCache redisCache;
@Autowired
private WeTicketClient weTicketClient;
/**
* 获取企业的jsapi_ticket
*
* @param url JS接口页面的完整URL
* @return
*/
@Log(title = "获取企业的jsapi_ticket", businessType = BusinessType.OTHER)
@GetMapping("/getAppTicket")
public AjaxResult getAppTicket(String url) {
String ticketVaule = redisCache.getCacheObject(WeConstans.AppTicketKey);
if (StringUtils.isEmpty(ticketVaule)) {
WeH5TicketDto ticketRes = weTicketClient.getJsapiTicket();
if (ticketRes != null && StringUtils.isNotEmpty(ticketRes.getTicket())) {
redisCache.setCacheObject(WeConstans.AppTicketKey, ticketRes.getTicket(), ticketRes.getExpiresIn(), TimeUnit.SECONDS);
}
ticketVaule = ticketRes.getTicket();
}
return AjaxResult.success(TicketUtils.getSignatureMap(ticketVaule, url));
}
/**
* 获取应用的jsapi_ticket
*
* @param url JS接口页面的完整URL
* @return
*/
@Log(title = "获取应用的jsapi_ticket", businessType = BusinessType.OTHER)
@GetMapping("/getAgentTicket")
public AjaxResult getAgentTicket(String url) {
String ticketVaule = redisCache.getCacheObject(WeConstans.AgentTicketKey);
if (StringUtils.isEmpty(ticketVaule)) {
WeH5TicketDto ticketRes = weTicketClient.getTicket();
if (ticketRes != null && StringUtils.isNotEmpty(ticketRes.getTicket())) {
redisCache.setCacheObject(WeConstans.AgentTicketKey, ticketRes.getTicket(), ticketRes.getExpiresIn(), TimeUnit.SECONDS);
}
ticketVaule = ticketRes.getTicket();
}
return AjaxResult.success(TicketUtils.getSignatureMap(ticketVaule, url));
}
}
......@@ -225,6 +225,10 @@ public class WeConstans {
*/
public static final long LIMIT = 1_000L;
public static final String AppTicketKey = "ticket:AppGet";
public static final String AgentTicketKey = "ticket:AgentGet";
/**
* 企微回调事件类型路由
*/
......
package com.linkwechat.common.utils.wecom;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.RandomStringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* @author danmo
* @description
* @date 2021/1/6 12:00
**/
@Slf4j
public class TicketUtils {
public static Map<String, Object> getSignatureMap(String ticketVaule, String url) {
String nonceStr = RandomStringUtils.randomAlphanumeric(10);
Long timestamp = System.currentTimeMillis() / 1000;
StringBuilder strBuild = new StringBuilder();
strBuild.append("jsapi_ticket=").append(ticketVaule)
.append("&noncestr=").append(nonceStr)
.append("&timestamp=").append(timestamp)
.append("&url=").append(url);
log.info("H5加密串:{}",strBuild.toString());
String signature = DigestUtils.sha1Hex(strBuild.toString());
return new HashMap(16) {{
put("nonceStr", nonceStr);
put("timestamp", timestamp);
put("signature", signature);
}};
}
}
package com.linkwechat.wecom.client;
import com.dtflys.forest.annotation.Request;
import com.linkwechat.wecom.domain.WeH5TicketDto;
/**
* @author danmo
* @description h5获取签名
* @date 2021/1/6 11:51
**/
public interface WeTicketClient {
/**
* 获取去企业jsapi_ticket
*
* @return
*/
@Request(url = "/get_jsapi_ticket")
WeH5TicketDto getJsapiTicket();
/**
* 获取应用jsapi_ticket
*
* @return
*/
@Request(url = "/ticket/get")
WeH5TicketDto getTicket();
}
package com.linkwechat.wecom.domain;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import lombok.Data;
/**
* @author danmo
* @description h5签名
* @date 2020/12/3 10:26
**/
@Data
public class WeH5TicketDto extends WeResultDto {
/**
* 生成签名所需的jsapi_ticket,最长为512字节
*/
private String ticket;
/**
* 凭证的有效时间(秒)
*/
private Integer expiresIn;
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!