1 加入转账自动收款。
2 群里只处理艾特自己的消息。 3 加入指令 : 余额
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.van333.mt2ql.wxMessage.mapper;
|
||||||
|
|
||||||
|
import cn.van333.mt2ql.wxMessage.model.WxMessageDataForTransfer;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 80787
|
||||||
|
* @description 针对表【wx_message_data_for_transfer】的数据库操作Mapper
|
||||||
|
* @createDate 2023-12-25 16:04:01
|
||||||
|
* @Entity cn.van333.mt2ql.wxMessage.model.WxMessageDataForTransfer
|
||||||
|
*/
|
||||||
|
public interface WxMessageDataForTransferMapper extends BaseMapper<WxMessageDataForTransfer> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -3,6 +3,8 @@ package cn.van333.mt2ql.wxMessage.model;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
/**
|
/**
|
||||||
* @author Leo
|
* @author Leo
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package cn.van333.mt2ql.wxMessage.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName wx_message_data_for_transfer
|
||||||
|
*/
|
||||||
|
@TableName(value ="wx_message_data_for_transfer")
|
||||||
|
@Data
|
||||||
|
public class WxMessageDataForTransfer implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对方wxid
|
||||||
|
*/
|
||||||
|
private String fromwxid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1|收到转账 2|对方接收转账 3|发出转账 4|自己接收转账 5|对方退还 6|自己退还
|
||||||
|
*/
|
||||||
|
private Integer msgsource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1|即时到账 2|延时到账
|
||||||
|
*/
|
||||||
|
private Integer transtype;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 金额,单位元
|
||||||
|
*/
|
||||||
|
private BigDecimal money;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转账备注
|
||||||
|
*/
|
||||||
|
private String memo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转账ID
|
||||||
|
*/
|
||||||
|
private String transferid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 10位时间戳
|
||||||
|
*/
|
||||||
|
private Integer invalidtime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object that) {
|
||||||
|
if (this == that) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (that == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != that.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
WxMessageDataForTransfer other = (WxMessageDataForTransfer) that;
|
||||||
|
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||||
|
&& (this.getFromwxid() == null ? other.getFromwxid() == null : this.getFromwxid().equals(other.getFromwxid()))
|
||||||
|
&& (this.getMsgsource() == null ? other.getMsgsource() == null : this.getMsgsource().equals(other.getMsgsource()))
|
||||||
|
&& (this.getTranstype() == null ? other.getTranstype() == null : this.getTranstype().equals(other.getTranstype()))
|
||||||
|
&& (this.getMoney() == null ? other.getMoney() == null : this.getMoney().equals(other.getMoney()))
|
||||||
|
&& (this.getMemo() == null ? other.getMemo() == null : this.getMemo().equals(other.getMemo()))
|
||||||
|
&& (this.getTransferid() == null ? other.getTransferid() == null : this.getTransferid().equals(other.getTransferid()))
|
||||||
|
&& (this.getInvalidtime() == null ? other.getInvalidtime() == null : this.getInvalidtime().equals(other.getInvalidtime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||||
|
result = prime * result + ((getFromwxid() == null) ? 0 : getFromwxid().hashCode());
|
||||||
|
result = prime * result + ((getMsgsource() == null) ? 0 : getMsgsource().hashCode());
|
||||||
|
result = prime * result + ((getTranstype() == null) ? 0 : getTranstype().hashCode());
|
||||||
|
result = prime * result + ((getMoney() == null) ? 0 : getMoney().hashCode());
|
||||||
|
result = prime * result + ((getMemo() == null) ? 0 : getMemo().hashCode());
|
||||||
|
result = prime * result + ((getTransferid() == null) ? 0 : getTransferid().hashCode());
|
||||||
|
result = prime * result + ((getInvalidtime() == null) ? 0 : getInvalidtime().hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(getClass().getSimpleName());
|
||||||
|
sb.append(" [");
|
||||||
|
sb.append("Hash = ").append(hashCode());
|
||||||
|
sb.append(", id=").append(id);
|
||||||
|
sb.append(", fromwxid=").append(fromwxid);
|
||||||
|
sb.append(", msgsource=").append(msgsource);
|
||||||
|
sb.append(", transtype=").append(transtype);
|
||||||
|
sb.append(", money=").append(money);
|
||||||
|
sb.append(", memo=").append(memo);
|
||||||
|
sb.append(", transferid=").append(transferid);
|
||||||
|
sb.append(", invalidtime=").append(invalidtime);
|
||||||
|
sb.append(", serialVersionUID=").append(serialVersionUID);
|
||||||
|
sb.append("]");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package cn.van333.mt2ql.wxMessage.service;
|
||||||
|
|
||||||
|
import cn.van333.mt2ql.wxMessage.model.WxMessageDataForTransfer;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 80787
|
||||||
|
* @description 针对表【wx_message_data_for_transfer】的数据库操作Service
|
||||||
|
* @createDate 2023-12-25 16:04:01
|
||||||
|
*/
|
||||||
|
public interface WxMessageDataForTransferService extends IService<WxMessageDataForTransfer> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package cn.van333.mt2ql.wxMessage.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import cn.van333.mt2ql.wxMessage.model.WxMessageDataForTransfer;
|
||||||
|
import cn.van333.mt2ql.wxMessage.service.WxMessageDataForTransferService;
|
||||||
|
import cn.van333.mt2ql.wxMessage.mapper.WxMessageDataForTransferMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 80787
|
||||||
|
* @description 针对表【wx_message_data_for_transfer】的数据库操作Service实现
|
||||||
|
* @createDate 2023-12-25 16:04:01
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class WxMessageDataForTransferServiceImpl extends ServiceImpl<WxMessageDataForTransferMapper, WxMessageDataForTransfer>
|
||||||
|
implements WxMessageDataForTransferService{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -9,6 +9,8 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Leo
|
* @author Leo
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
@@ -50,6 +52,8 @@ public class WXUtil {
|
|||||||
private static final RedisCache redisCache = SpringUtil.getBean(RedisCache.class);
|
private static final RedisCache redisCache = SpringUtil.getBean(RedisCache.class);
|
||||||
private static final Logger logger = LoggerFactory.getLogger(WXUtil.class);
|
private static final Logger logger = LoggerFactory.getLogger(WXUtil.class);
|
||||||
|
|
||||||
|
private static final String super_admin_wxid = "wxid_ytpc72mdoskt22";
|
||||||
|
|
||||||
|
|
||||||
// 获取微信列表
|
// 获取微信列表
|
||||||
public JSONObject getWxList() {
|
public JSONObject getWxList() {
|
||||||
@@ -63,8 +67,12 @@ public class WXUtil {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送文本消息
|
// 发送文本消息 msgType 1:私聊 2:群发
|
||||||
public JSONObject sendTextMessage(String wxid, String content) {
|
public JSONObject sendTextMessage(String wxid, String content, Integer msgType, String fromwxid) {
|
||||||
|
// 如果是自己的微信,所有信息都加上少爷
|
||||||
|
if (wxid.equals(super_admin_wxid) || fromwxid.equals(super_admin_wxid)) {
|
||||||
|
content = " 少爷好!\n " + content;
|
||||||
|
}
|
||||||
String botWxid = "";
|
String botWxid = "";
|
||||||
JSONObject wxList = getWxList();
|
JSONObject wxList = getWxList();
|
||||||
JSONObject wxBotInfo = (JSONObject) wxList.getJSONArray("result").get(0);
|
JSONObject wxBotInfo = (JSONObject) wxList.getJSONArray("result").get(0);
|
||||||
@@ -73,9 +81,15 @@ public class WXUtil {
|
|||||||
//
|
//
|
||||||
WxReqDate wxReqDate = createWxReqData(WXReqType.SEND_TEXT_MESSAGE);
|
WxReqDate wxReqDate = createWxReqData(WXReqType.SEND_TEXT_MESSAGE);
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("wxid", wxid);
|
if ((msgType.equals(1))) {
|
||||||
|
jsonObject.put("wxid", wxid);
|
||||||
|
content = content;
|
||||||
|
}
|
||||||
//[@,wxid=对象wxid,nick=对象昵称,isAuto=true]
|
//[@,wxid=对象wxid,nick=对象昵称,isAuto=true]
|
||||||
content = "[@,wxid=" + wxid + ",nick=6,isAuto=true] " + content;
|
if ((msgType.equals(2))) {
|
||||||
|
jsonObject.put("wxid", fromwxid);
|
||||||
|
content = "[@,wxid=" + wxid + ",nick=6,isAuto=true] " + content;
|
||||||
|
}
|
||||||
jsonObject.put("msg", content);
|
jsonObject.put("msg", content);
|
||||||
wxReqDate.setData(jsonObject);
|
wxReqDate.setData(jsonObject);
|
||||||
while (Util.isNotEmpty(botWxid)) {
|
while (Util.isNotEmpty(botWxid)) {
|
||||||
@@ -90,6 +104,11 @@ public class WXUtil {
|
|||||||
//JSONObject jsonObject = HttpUtil.sendPost(url, wxReqDate.getData());
|
//JSONObject jsonObject = HttpUtil.sendPost(url, wxReqDate.getData());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -117,6 +136,36 @@ public class WXUtil {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* "type": "Q0016",
|
||||||
|
* "data": {
|
||||||
|
* "wxid": "wxid_3sx9sjgq99kd22",
|
||||||
|
* "transferid": "1000050001202207161417697440336"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public JSONObject queRenShouKuan(String wxid, String transferid) {
|
||||||
|
String botWxid = "";
|
||||||
|
JSONObject wxList = getWxList();
|
||||||
|
JSONObject wxBotInfo = (JSONObject) wxList.getJSONArray("result").get(0);
|
||||||
|
botWxid = wxBotInfo.getString("wxid");
|
||||||
|
WxReqDate wxReqDate = createWxReqData(WXReqType.CONFIRM_RECEIPT);
|
||||||
|
HashMap<String,String> body = new HashMap<>();
|
||||||
|
body.put("wxid", wxid);
|
||||||
|
body.put("transferid", transferid);
|
||||||
|
JSONObject jsonObject = new JSONObject(body);
|
||||||
|
wxReqDate.setData(jsonObject);
|
||||||
|
String responseStr = HttpRequest.post(WX_BASE_URL + "?wxid=" + botWxid).body(JSON.toJSONString(wxReqDate)).execute().body();
|
||||||
|
logger.info("确认收款结果:responseStr: {}", responseStr);
|
||||||
|
if (ObjectUtil.isNotEmpty(responseStr)) {
|
||||||
|
return JSON.parseObject(responseStr);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public WxReqDate createWxReqData(WXReqType wxReqType) {
|
public WxReqDate createWxReqData(WXReqType wxReqType) {
|
||||||
|
|
||||||
WxReqDate wxReqDate = new WxReqDate(wxReqType.getKey(), null);
|
WxReqDate wxReqDate = new WxReqDate(wxReqType.getKey(), null);
|
||||||
|
|||||||
@@ -4,21 +4,22 @@ import cn.hutool.extra.spring.SpringUtil;
|
|||||||
import cn.van333.mt2ql.wxMessage.enums.EventType;
|
import cn.van333.mt2ql.wxMessage.enums.EventType;
|
||||||
import cn.van333.mt2ql.wxMessage.model.WxMessage;
|
import cn.van333.mt2ql.wxMessage.model.WxMessage;
|
||||||
import cn.van333.mt2ql.wxMessage.model.WxMessageDataForChat;
|
import cn.van333.mt2ql.wxMessage.model.WxMessageDataForChat;
|
||||||
|
import cn.van333.mt2ql.wxMessage.model.WxMessageDataForTransfer;
|
||||||
import cn.van333.mt2ql.wxMessage.model.WxUser;
|
import cn.van333.mt2ql.wxMessage.model.WxUser;
|
||||||
import cn.van333.mt2ql.wxMessage.service.WxMessageDataForChatService;
|
import cn.van333.mt2ql.wxMessage.service.WxMessageDataForChatService;
|
||||||
import cn.van333.mt2ql.wxMessage.service.WxUserService;
|
import cn.van333.mt2ql.wxMessage.service.WxUserService;
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Leo
|
* @author Leo
|
||||||
@@ -49,7 +50,7 @@ public class WxMessageConsumer {
|
|||||||
|
|
||||||
//@Async("threadPoolTaskExecutor")
|
//@Async("threadPoolTaskExecutor")
|
||||||
public void consume(WxMessage wxMessage) {
|
public void consume(WxMessage wxMessage) {
|
||||||
//logger.info("接收到消息 : {}", wxMessage);
|
logger.info("接收到消息 : {}", wxMessage);
|
||||||
if (wxMessage.getEvent() == null) {
|
if (wxMessage.getEvent() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -64,15 +65,94 @@ public class WxMessageConsumer {
|
|||||||
if (event.equals(EventType.PRIVATE_MESSAGE.getKey())) {
|
if (event.equals(EventType.PRIVATE_MESSAGE.getKey())) {
|
||||||
handlePrivateMessage(wxMessage);
|
handlePrivateMessage(wxMessage);
|
||||||
}
|
}
|
||||||
|
if (event.equals(EventType.GROUP_MESSAGE.getKey())) {
|
||||||
|
handleGroupMessage(wxMessage);
|
||||||
|
}
|
||||||
|
if (event.equals(EventType.TRANSFER_EVENT.getKey())) {
|
||||||
|
handleTransferEvent(wxMessage);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Boolean heiMingDan(String wxid) {
|
||||||
|
Boolean flag = false;
|
||||||
|
WxUser wxUser = wxUserService.getOne(Wrappers.query(new WxUser()).eq("wxid", wxid));
|
||||||
|
if (Util.isNotEmpty(wxUser)) {
|
||||||
|
if (wxUser.getStatus().equals(2)) {
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param wxMessage
|
||||||
|
* @return
|
||||||
|
* @throws
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
private void handleTransferEvent(WxMessage wxMessage) {
|
||||||
|
Integer msgType = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {
|
||||||
|
* "fromWxid": "wxid_ytpc72mdoskt22", 对方wxid
|
||||||
|
* "msgSource": 1, 1|收到转账 2|对方接收转账 3|发出转账 4|自己接收转账 5|对方退还 6|自己退还
|
||||||
|
* "transType": 1, 1|即时到账 2|延时到账
|
||||||
|
* "money": "2.00", 金额,单位元
|
||||||
|
* "memo": "", 转账备注
|
||||||
|
* "transferid": "1000050001202312250424037787039", 转账ID
|
||||||
|
* "invalidtime": "1703577220" 10位时间戳
|
||||||
|
* }*/
|
||||||
|
JSONObject data = wxMessage.getData().getJSONObject("data");
|
||||||
|
if (data == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WxMessageDataForTransfer wxMessageDataForTransfer = data.to(WxMessageDataForTransfer.class);
|
||||||
|
|
||||||
|
String result = null;
|
||||||
|
String wxid = wxMessageDataForTransfer.getFromwxid();
|
||||||
|
|
||||||
|
WXUtil wxUtil = new WXUtil();
|
||||||
|
|
||||||
|
if (heiMingDan(wxid)) {
|
||||||
|
result = "您已被拉黑,请联系客服!";
|
||||||
|
} else {
|
||||||
|
if (wxMessageDataForTransfer.getTranstype().equals(2)) {
|
||||||
|
result = "请勿使用延时到账功能。累计三次将永久拉黑!";
|
||||||
|
} else {
|
||||||
|
|
||||||
|
JSONObject shouKuanResult = wxUtil.queRenShouKuan(wxid, wxMessageDataForTransfer.getTransferid());
|
||||||
|
if (shouKuanResult == null) {
|
||||||
|
result = "查询转账失败,请稍后再试。";
|
||||||
|
}
|
||||||
|
if (shouKuanResult != null && shouKuanResult.getInteger("code") == 200) {
|
||||||
|
BigDecimal money = wxMessageDataForTransfer.getMoney();
|
||||||
|
if (money.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
WxUser wxUser = wxUserService.getOne(Wrappers.query(new WxUser()).eq("wxid", wxid));
|
||||||
|
wxUser.setMoneyLeiji(wxUser.getMoneyLeiji().add(money));
|
||||||
|
wxUser.setMoneyShengyu(wxUser.getMoneyShengyu().add(money));
|
||||||
|
wxUser.setCountChongzhi(wxUser.getCountChongzhi().add(BigDecimal.ONE));
|
||||||
|
wxUserService.updateById(wxUser);
|
||||||
|
result = "收到转账" + money + "元,已成功存入账户。感谢您的使用。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
wxUtil.sendTextMessage(wxid, result, msgType, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理私聊消息
|
* 处理私聊消息
|
||||||
*
|
*
|
||||||
* @param wxMessage
|
* @param wxMessage
|
||||||
*/
|
*/
|
||||||
private void handlePrivateMessage(WxMessage wxMessage) {
|
private void handlePrivateMessage(WxMessage wxMessage) {
|
||||||
|
Integer msgType = 1;
|
||||||
/**
|
/**
|
||||||
* 接收到消息 : WxMessage(event=10009, wxid=wxid_kr145nk7l0an31, data={"type":"D0003","des":"收到消息","data":{"timeStamp":"1703128368100","fromType":1,"msgT两次ype":1,"msgSource":0,"fromWxid":"wxid_ytpc72mdoskt22","finalFromWxid":"","atWxidList":[],"silence":0,"membercount":0,"signature":"v1_vXrWK/iB","msg":"嗨鲁个迷紫123","msgBase64":"5Zeo6bKB5Liq6L+357SrMTIz"},"timestamp":"1703128368112","wxid":"wxid_kr145nk7l0an31","port":16888,"pid":10468,"flag":"7777"})
|
* 接收到消息 : WxMessage(event=10009, wxid=wxid_kr145nk7l0an31, data={"type":"D0003","des":"收到消息","data":{"timeStamp":"1703128368100","fromType":1,"msgT两次ype":1,"msgSource":0,"fromWxid":"wxid_ytpc72mdoskt22","finalFromWxid":"","atWxidList":[],"silence":0,"membercount":0,"signature":"v1_vXrWK/iB","msg":"嗨鲁个迷紫123","msgBase64":"5Zeo6bKB5Liq6L+357SrMTIz"},"timestamp":"1703128368112","wxid":"wxid_kr145nk7l0an31","port":16888,"pid":10468,"flag":"7777"})
|
||||||
* 需要get 两次 data 字段*/
|
* 需要get 两次 data 字段*/
|
||||||
@@ -124,21 +204,157 @@ public class WxMessageConsumer {
|
|||||||
String httpData = all[1];
|
String httpData = all[1];
|
||||||
String[] httpDataArr = httpData.split("&");
|
String[] httpDataArr = httpData.split("&");
|
||||||
if (httpDataArr.length == 2) {
|
if (httpDataArr.length == 2) {
|
||||||
mt20(wxid, httpDataArr[0].split("=")[1], httpDataArr[1].split("=")[1]);
|
String result = mt20(wxid, httpDataArr[0].split("=")[1], httpDataArr[1].split("=")[1]);
|
||||||
|
WXUtil wxUtil = new WXUtil();
|
||||||
|
wxUtil.sendTextMessage(wxid, result, msgType, null);
|
||||||
|
} else {
|
||||||
|
WXUtil wxUtil = new WXUtil();
|
||||||
|
wxUtil.sendTextMessage(wxid, "请检查提交的数据格式是否正确。", msgType, null);
|
||||||
}
|
}
|
||||||
//mt20(wxid, userId, token);
|
|
||||||
//if (runResult) {
|
|
||||||
// logger.info("领券成功");
|
|
||||||
// String newMsg = msg.replace("https://i.meituan.com/mttouch/page/account", "https://i.meituan.com/mttouch/page/account?userId=" + userId + "&token=" + token);
|
|
||||||
// wxMessageDataForChat.setMsg(newMsg);
|
|
||||||
// wxMessageDataForChatService.updateById(wxMessageDataForChat);
|
|
||||||
//} else {
|
|
||||||
// logger.info("领券失败");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
} else if ("余额".equals(msg)) {
|
||||||
|
String wxid = null;
|
||||||
|
if (wxMessageDataForChat.getFromtype() == 1) {
|
||||||
|
wxid = wxMessageDataForChat.getFromwxid();
|
||||||
|
} else if (wxMessageDataForChat.getFromtype() == 2) {
|
||||||
|
wxid = wxMessageDataForChat.getFinalfromwxid();
|
||||||
|
}
|
||||||
|
WxUser wxUser = wxUserService.getOne(Wrappers.query(new WxUser()).eq("wxid", wxid));
|
||||||
|
String result = "";
|
||||||
|
if (Util.isNotEmpty(wxUser)) {
|
||||||
|
result = "您的余额为:" + wxUser.getMoneyLeiji() + "元\r";
|
||||||
|
result = result + " 您的消费次数为:" + wxUser.getCountXiaofei() + "次\r";
|
||||||
|
result = result + " 您的充值次数为:" + wxUser.getCountChongzhi() + "次\r";
|
||||||
|
result = result + " 您的累计充值为:" + wxUser.getMoneyLeiji() + "元";
|
||||||
|
} else {
|
||||||
|
result = "暂未查询到充值记录。\r";
|
||||||
|
}
|
||||||
|
|
||||||
|
WXUtil wxUtil = new WXUtil();
|
||||||
|
wxUtil.sendTextMessage(wxid, result, msgType, null);
|
||||||
|
}
|
||||||
|
wxMessageDataForChatService.save(wxMessageDataForChat);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param wxMessage
|
||||||
|
* @return
|
||||||
|
* @throws
|
||||||
|
* @description 处理群聊消息
|
||||||
|
*/
|
||||||
|
private void handleGroupMessage(WxMessage wxMessage) {
|
||||||
|
Integer msgType = 2;
|
||||||
|
/**
|
||||||
|
* 接收到消息 : WxMessage(event=10009, wxid=wxid_kr145nk7l0an31, data={"type":"D0003","des":"收到消息","data":{"timeStamp":"1703128368100","fromType":1,"msgT两次ype":1,"msgSource":0,"fromWxid":"wxid_ytpc72mdoskt22","finalFromWxid":"","atWxidList":[],"silence":0,"membercount":0,"signature":"v1_vXrWK/iB","msg":"嗨鲁个迷紫123","msgBase64":"5Zeo6bKB5Liq6L+357SrMTIz"},"timestamp":"1703128368112","wxid":"wxid_kr145nk7l0an31","port":16888,"pid":10468,"flag":"7777"})
|
||||||
|
* 需要get 两次 data 字段*/
|
||||||
|
JSONObject data = wxMessage.getData().getJSONObject("data");
|
||||||
|
if (data == null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMessageDataForChatService.save(wxMessageDataForChat);
|
|
||||||
|
/**{"type":"D0003","des":"收到消息","data":{"timeStamp":"1702957325031","fromType":1,"msgType":1,"msgSource":0,"fromWxid":"wxid_ytpc72mdoskt22","finalFromWxid":"","atWxidList":[],"silence":0,"membercount":0,"signature":"v1_OJXJYpvM","msg":"在不","msgBase64":"5Zyo5LiN"},"timestamp":"1702957325041","wxid":"wxid_kr145nk7l0an31","port":16888,"pid":10468,"flag":"7777"}
|
||||||
|
* */
|
||||||
|
WxMessageDataForChat wxMessageDataForChat = data.to(WxMessageDataForChat.class);
|
||||||
|
|
||||||
|
// 做业务处理
|
||||||
|
logger.info("处理消息: {}", wxMessageDataForChat.toString());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* timeStamp 收到这条消息的13位现行时间戳
|
||||||
|
* fromType 来源类型:1|私聊 2|群聊 3|公众号
|
||||||
|
* msgType 消息类型:1|文本 3|图片 34|语音 42|名片 43|视频 47|动态表情 48|地理位置 49|分享链接或附件 2001|红包 2002|小程序 2003|群邀请 10000|系统消息
|
||||||
|
* msgSource 消息来源:0|别人发送 1|自己手机发送
|
||||||
|
* fromWxid fromType=1时为好友wxid,fromType=2时为群wxid,fromType=3时公众号wxid
|
||||||
|
* finalFromWxid 仅fromType=2时有效,为群内发言人wxid
|
||||||
|
* atWxidList 仅fromType=2,且msgSource=0时有效,为消息中艾特人wxid列表
|
||||||
|
* silence 仅fromType=2时有效,0
|
||||||
|
* membercount 仅fromType=2时有效,群成员数量
|
||||||
|
* signature 消息签名
|
||||||
|
* msg 消息内容
|
||||||
|
* msgBase64 消息内容的Base64
|
||||||
|
* */
|
||||||
|
if (Util.isAnyEmpty(wxMessageDataForChat.getMsg(), wxMessageDataForChat.getFromwxid(), wxMessageDataForChat.getFromtype())) {
|
||||||
|
logger.info("消息内容为空,不处理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String atwxidlist = wxMessageDataForChat.getAtwxidlist();
|
||||||
|
if (Util.isNotEmpty((atwxidlist))) {
|
||||||
|
JSONObject wxList = new WXUtil().getWxList();
|
||||||
|
JSONObject wxBotInfo = (JSONObject) wxList.getJSONArray("result").get(0);
|
||||||
|
String botWxid = wxBotInfo.getString("wxid");
|
||||||
|
|
||||||
|
if (atwxidlist.contains(botWxid)) {
|
||||||
|
String[] split = wxMessageDataForChat.getMsg().split(" ");
|
||||||
|
String msg;
|
||||||
|
if (split.length == 2){
|
||||||
|
msg = split[1];
|
||||||
|
}else {
|
||||||
|
String[] newArray = new String[split.length - 1];
|
||||||
|
System.arraycopy(split, 1, newArray, 0, newArray.length);
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
Iterator<String> iterator = Arrays.stream(newArray).iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
String s = iterator.next();
|
||||||
|
stringBuilder.append(s).append(" ");
|
||||||
|
}
|
||||||
|
msg = stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//美团 20-7 + https://i.meituan.com/mttouch/page/account?userId=3822095266&token=AgHdIkm2tAGHc9SQSiG7M8xCx1LbTue9D2HPOAun2eYl3ou7BeEw1uGrGZH-DxmEiUgsbA1v9SM4DQAAAAC6HAAAz0rTXmkB_CIHin08hCu68mFv5k6nUc2q6_CfZqEdBcngRK_xD8Sx5fE4rfdq-yAJ, msgbase64=576O5ZuiIDIwLTcgKyBodHRwczovL2kubWVpdHVhbi5jb20vbXR0b3VjaC9wYWdlL2FjY291bnQ/dXNlcklkPTM4MjIwOTUyNjYmdG9rZW49QWdIZElrbTJ0QUdIYzlTUVNpRzdNOHhDeDFMYlR1ZTlEMkhQT0F1bjJlWWwzb3U3QmVFdzF1R3JHWkgtRHhtRWlVZ3NiQTF2OVNNNERRQUFBQUM2SEFBQXowclRYbWtCX0NJSGluMDhoQ3U2OG1GdjVrNm5VYzJxNl9DZlpxRWRCY25nUktfeEQ4U3g1ZkU0cmZkcS15QUo=
|
||||||
|
if (msg.startsWith("美团 20-7 ")) {
|
||||||
|
logger.info("处理美团的消息");
|
||||||
|
msg = msg.substring(msg.indexOf("https://i.meituan.com/mttouch/page/account"));
|
||||||
|
String[] all = msg.split("\\?");
|
||||||
|
|
||||||
|
if (all.length == 2) {
|
||||||
|
String wxid = null;
|
||||||
|
if (wxMessageDataForChat.getFromtype() == 1) {
|
||||||
|
wxid = wxMessageDataForChat.getFromwxid();
|
||||||
|
} else if (wxMessageDataForChat.getFromtype() == 2) {
|
||||||
|
wxid = wxMessageDataForChat.getFinalfromwxid();
|
||||||
|
}
|
||||||
|
String httpData = all[1];
|
||||||
|
String[] httpDataArr = httpData.split("&");
|
||||||
|
if (httpDataArr.length == 2) {
|
||||||
|
String result = mt20(wxMessageDataForChat.getFinalfromwxid(), httpDataArr[0].split("=")[1], httpDataArr[1].split("=")[1]);
|
||||||
|
WXUtil wxUtil = new WXUtil();
|
||||||
|
wxUtil.sendTextMessage(wxMessageDataForChat.getFinalfromwxid(), result, msgType, wxMessageDataForChat.getFromwxid());
|
||||||
|
} else {
|
||||||
|
WXUtil wxUtil = new WXUtil();
|
||||||
|
wxUtil.sendTextMessage(wxMessageDataForChat.getFinalfromwxid(), "请检查提交的数据格式是否正确。", msgType, wxMessageDataForChat.getFromwxid());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if ("[转账待你接收,可在手机上查看]".equals(msg)) {
|
||||||
|
WXUtil wxUtil = new WXUtil();
|
||||||
|
wxUtil.sendTextMessage(wxMessageDataForChat.getFinalfromwxid(), "暂不支持群内转账功能,请私聊进行转账充值。", msgType, wxMessageDataForChat.getFromwxid());
|
||||||
|
} else if ("余额".equals(msg)) {
|
||||||
|
String wxid = null;
|
||||||
|
if (wxMessageDataForChat.getFromtype() == 1) {
|
||||||
|
wxid = wxMessageDataForChat.getFromwxid();
|
||||||
|
} else if (wxMessageDataForChat.getFromtype() == 2) {
|
||||||
|
wxid = wxMessageDataForChat.getFinalfromwxid();
|
||||||
|
}
|
||||||
|
WxUser wxUser = wxUserService.getOne(Wrappers.query(new WxUser()).eq("wxid", wxid));
|
||||||
|
String result = "";
|
||||||
|
if (Util.isNotEmpty(wxUser)) {
|
||||||
|
result = "您的余额为:" + wxUser.getMoneyLeiji() + "元\r";
|
||||||
|
result = result + " 您的消费次数为:" + wxUser.getCountXiaofei() + "次\r";
|
||||||
|
result = result + " 您的充值次数为:" + wxUser.getCountChongzhi() + "次\r";
|
||||||
|
result = result + " 您的累计充值为:" + wxUser.getMoneyLeiji() + "元";
|
||||||
|
} else {
|
||||||
|
result = "暂未查询到充值记录。\r";
|
||||||
|
}
|
||||||
|
|
||||||
|
WXUtil wxUtil = new WXUtil();
|
||||||
|
wxUtil.sendTextMessage(wxid, result, msgType, wxMessageDataForChat.getFromwxid());
|
||||||
|
}
|
||||||
|
wxMessageDataForChatService.save(wxMessageDataForChat);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +378,7 @@ public class WxMessageConsumer {
|
|||||||
Boolean isRun = (Boolean) checkYuE.get("isRun");
|
Boolean isRun = (Boolean) checkYuE.get("isRun");
|
||||||
String info = (String) checkYuE.get("info");
|
String info = (String) checkYuE.get("info");
|
||||||
BigDecimal yuE = (BigDecimal) checkYuE.get("yuE");
|
BigDecimal yuE = (BigDecimal) checkYuE.get("yuE");
|
||||||
isRun = true;
|
//isRun = true;
|
||||||
|
|
||||||
// 余额可以支持一次扣费
|
// 余额可以支持一次扣费
|
||||||
if (isRun) {
|
if (isRun) {
|
||||||
@@ -171,7 +387,7 @@ public class WxMessageConsumer {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 调用青龙 失败
|
// 调用青龙 失败
|
||||||
logger.info("调用青龙失败");
|
logger.info("余额不支持一次扣费");
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,18 +468,15 @@ public class WxMessageConsumer {
|
|||||||
String mobile = loginedUserInfo.get("mobile");
|
String mobile = loginedUserInfo.get("mobile");
|
||||||
String nickName = loginedUserInfo.get("nickName");
|
String nickName = loginedUserInfo.get("nickName");
|
||||||
String remark = nickName + "+" + mobile;
|
String remark = nickName + "+" + mobile;
|
||||||
|
return remark;
|
||||||
//qlUtil.addEnv(token, meituanCookie, remark);
|
//qlUtil.addEnv(token, meituanCookie, remark);
|
||||||
wxUtil.sendTextMessage(wxid, remark);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
wxUtil.sendTextMessage(wxid, "获取用户信息失败");
|
|
||||||
|
|
||||||
return "获取用户信息失败";
|
return "获取用户信息失败";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
23
src/main/resources/mapper/WxMessageDataForTransferMapper.xml
Normal file
23
src/main/resources/mapper/WxMessageDataForTransferMapper.xml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="cn.van333.mt2ql.wxMessage.mapper.WxMessageDataForTransferMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="cn.van333.mt2ql.wxMessage.model.WxMessageDataForTransfer">
|
||||||
|
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||||
|
<result property="fromwxid" column="fromWxid" jdbcType="VARCHAR"/>
|
||||||
|
<result property="msgsource" column="msgSource" jdbcType="INTEGER"/>
|
||||||
|
<result property="transtype" column="transType" jdbcType="INTEGER"/>
|
||||||
|
<result property="money" column="money" jdbcType="DECIMAL"/>
|
||||||
|
<result property="memo" column="memo" jdbcType="VARCHAR"/>
|
||||||
|
<result property="transferid" column="transferid" jdbcType="VARCHAR"/>
|
||||||
|
<result property="invalidtime" column="invalidtime" jdbcType="INTEGER"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,fromWxid,msgSource,
|
||||||
|
transType,money,memo,
|
||||||
|
transferid,invalidtime
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user