parent
35602b9bf8
commit
17cbf7a390
@ -0,0 +1,153 @@
|
||||
package cc.yunxi.controller;
|
||||
|
||||
|
||||
import cc.yunxi.common.domain.CommonResult;
|
||||
import cc.yunxi.domain.vo.vxmessage.AccessToken;
|
||||
import cc.yunxi.domain.vo.vxmessage.MessageTemplate;
|
||||
import cc.yunxi.domain.vo.vxmessage.OrderNew;
|
||||
import cc.yunxi.domain.vo.vxmessage.ResultVo;
|
||||
import cc.yunxi.utils.VerifyUtil;
|
||||
import cc.yunxi.utils.WeChatMessageUtil;
|
||||
import cc.yunxi.utils.WeChatUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Api(tags = "对接微信推送认证")
|
||||
@RestController
|
||||
@RequestMapping("/wx-message")
|
||||
@Slf4j
|
||||
public class WxMessageController {
|
||||
|
||||
|
||||
@Resource
|
||||
private WeChatMessageUtil weChatMessageUtil;
|
||||
|
||||
@Resource
|
||||
private VerifyUtil verifyUtil;
|
||||
|
||||
/**
|
||||
* 预约端对接微信推送消息验证
|
||||
*
|
||||
* @param signature 签名
|
||||
* @param timestamp 时间戳
|
||||
* @param nonce 随机数
|
||||
* @param echostr 随机字符串
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/clientReceive")
|
||||
public String clientVerify(@RequestParam String signature,
|
||||
@RequestParam String timestamp,
|
||||
@RequestParam String nonce,
|
||||
@RequestParam String echostr) {
|
||||
log.info("微信推送验证");
|
||||
boolean isOfficial = verifyUtil.checkSignature("client", signature, timestamp, nonce);
|
||||
if (isOfficial) return echostr;
|
||||
else {
|
||||
log.error("微信推送验证失败!非官方推送,{},{},{},{}", signature, timestamp, nonce, echostr);
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 回收端对接微信推送消息验证
|
||||
*
|
||||
* @param signature 签名
|
||||
* @param timestamp 时间戳
|
||||
* @param nonce 随机数
|
||||
* @param echostr 随机字符串
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/recyclerReceive")
|
||||
public String recyclerVerify(@RequestParam String signature,
|
||||
@RequestParam String timestamp,
|
||||
@RequestParam String nonce,
|
||||
@RequestParam String echostr) {
|
||||
log.info("微信推送验证");
|
||||
boolean isOfficial = verifyUtil.checkSignature("recycler", signature, timestamp, nonce);
|
||||
if (isOfficial) return echostr;
|
||||
else {
|
||||
log.error("微信推送验证失败!非官方推送,{},{},{},{}", signature, timestamp, nonce, echostr);
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
//散户端端接收微信平台消息
|
||||
@PostMapping("/clientReceive")
|
||||
public String clientReceive(@RequestParam("timestamp") String timestamp,
|
||||
@RequestParam("nonce") String nonce,
|
||||
@RequestParam("openid") String openid,
|
||||
@RequestParam("encrypt_type") String encryptType,
|
||||
@RequestParam("msg_signature") String msgSignature,
|
||||
@RequestBody String encryptedData) {
|
||||
JSONObject _encryptedData = JSONUtil.parseObj(encryptedData);
|
||||
String encrypt = _encryptedData.getStr("Encrypt");
|
||||
log.info("微信推送验证");
|
||||
boolean isOfficial = verifyUtil.checkSignature("client", timestamp, nonce, encrypt,msgSignature);
|
||||
if (!isOfficial) {
|
||||
log.error("接收推送消息失败!非官方推送,{},{},{},{}", timestamp, nonce, encrypt, msgSignature);
|
||||
return "error";
|
||||
}
|
||||
String message = weChatMessageUtil.decryptMessage(encrypt, "recycler");
|
||||
log.info("收到微信推送消息,{}", message);
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
//回收端接收微信平台消息
|
||||
@PostMapping("/recyclerReceive")
|
||||
public String recyclerReceive(@RequestParam("timestamp") String timestamp,
|
||||
@RequestParam("nonce") String nonce,
|
||||
@RequestParam("openid") String openid,
|
||||
@RequestParam("encrypt_type") String encryptType,
|
||||
@RequestParam("msg_signature") String msgSignature,
|
||||
@RequestBody String encryptedData) {
|
||||
JSONObject _encryptedData = JSONUtil.parseObj(encryptedData);
|
||||
String encrypt = _encryptedData.getStr("Encrypt");
|
||||
log.info("微信推送验证");
|
||||
boolean isOfficial = verifyUtil.checkSignature("recycler", timestamp, nonce, encrypt,msgSignature);
|
||||
if (!isOfficial) {
|
||||
log.error("接收推送消息失败!非官方推送,{},{},{},{}", timestamp, nonce, encrypt, msgSignature);
|
||||
return "error";
|
||||
}
|
||||
|
||||
String message = weChatMessageUtil.decryptMessage(encrypt, "recycler");
|
||||
log.info("收到微信推送消息,{}", message);
|
||||
return "success";
|
||||
}
|
||||
|
||||
@PostMapping("/getToken")
|
||||
public CommonResult<AccessToken> getToken(@RequestBody String message) {
|
||||
AccessToken client = weChatMessageUtil.getAccessToken("client");
|
||||
return CommonResult.success(client);
|
||||
}
|
||||
|
||||
@PostMapping("/send")
|
||||
public CommonResult<ResultVo> sendMessage(@RequestBody String message) {
|
||||
AccessToken client = weChatMessageUtil.getAccessToken("client");
|
||||
|
||||
OrderNew orderNew = new OrderNew();
|
||||
orderNew.setCharacter_string22("11");//订单号
|
||||
orderNew.setTime1("2024/06/04 16:30~17:30");//预约时间
|
||||
orderNew.setName15("上门回收");//服务名称
|
||||
orderNew.setThing9("地址");//预约地址
|
||||
orderNew.setPhone_number43("13183060802");//联系电话
|
||||
MessageTemplate template = new MessageTemplate();
|
||||
template.setTemplate_id(OrderNew.TEMPLATE_ID);
|
||||
template.setData(orderNew);
|
||||
template.setTouser("oYkV866Jjz197Iya3kJQwdypNPq8");
|
||||
template.setMiniprogram_state("trial");
|
||||
template.setPage("/pages/orderDetail/orderDetail");
|
||||
template.setLang("zh_CN");
|
||||
|
||||
ResultVo result = weChatMessageUtil.sendMessage(template, "client");
|
||||
|
||||
return CommonResult.success(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package cc.yunxi.domain.vo.vxmessage;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel(description = "订单信息基类")
|
||||
public class BaseMessage {
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package cc.yunxi.domain.vo.vxmessage;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel("订单完成")
|
||||
public class FinishOrder extends BaseMessage{
|
||||
|
||||
@ApiModelProperty("订单号")
|
||||
private String character_string5;
|
||||
@ApiModelProperty("订单状态")
|
||||
private String thing3;
|
||||
@ApiModelProperty("实付金额")
|
||||
private String amount22;
|
||||
@ApiModelProperty("服务方")
|
||||
private String thing10;
|
||||
@ApiModelProperty("完成时间")
|
||||
private String date9;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cc.yunxi.domain.vo.vxmessage;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel("订单取消")
|
||||
public class OrderCancel extends BaseMessage {
|
||||
@ApiModelProperty("订单编号")
|
||||
private String character_string3;
|
||||
@ApiModelProperty("订单状态")
|
||||
private String phrase4;
|
||||
@ApiModelProperty("服务地址")
|
||||
private String thing29;
|
||||
@ApiModelProperty("预约时间")
|
||||
private String date10;
|
||||
@ApiModelProperty("操作人")
|
||||
private String thing25;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package cc.yunxi.domain.vo.vxmessage;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel(description = "新订单预约成功通知消息模版")
|
||||
public class OrderNew extends BaseMessage{
|
||||
|
||||
@JsonIgnore//不在data属性中
|
||||
@ApiModelProperty("消息模版ID")
|
||||
public static final String TEMPLATE_ID = "TfLbZu3DxLSp4TnuTVCsDTY2U4zSV2M7MNTrGHaUL5s";
|
||||
@ApiModelProperty("订单编号")
|
||||
private String character_string22;
|
||||
@ApiModelProperty("预约时间")
|
||||
private String time1;
|
||||
@ApiModelProperty("服务名称")
|
||||
private String name15;
|
||||
@ApiModelProperty("预约地址")
|
||||
private String thing9;
|
||||
@ApiModelProperty("联系电话")
|
||||
private String phone_number43;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package cc.yunxi.domain.vo.vxmessage;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel("已接单消息模板")
|
||||
@Data
|
||||
public class OrderTaken extends BaseMessage{
|
||||
@ApiModelProperty("订单号")
|
||||
private String character_string5;
|
||||
@ApiModelProperty("订单状态")
|
||||
private String thing4;
|
||||
@ApiModelProperty("联系人")
|
||||
private String thing18;
|
||||
@ApiModelProperty("联系电话")
|
||||
private String phone_number14;
|
||||
@ApiModelProperty("服务时间")
|
||||
private String thing6;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cc.yunxi.domain.vo.vxmessage;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel("发送订阅消息的结果")
|
||||
@Data
|
||||
public class ResultVo {
|
||||
@ApiModelProperty("错误代码")
|
||||
private int errcode;
|
||||
@ApiModelProperty("错误描述")
|
||||
private String errmsg;
|
||||
}
|
Loading…
Reference in new issue