依赖的组件
<dependency>
<groupId>com.aliyun.mns</groupId>
<artifactId>aliyun-sdk-mns</artifactId>
<version>1.1.7</version>
</dependency>
添加进行消息同步发送的service
package net.sahv.realnetwork.service;
import com.alibaba.fastjson.JSON;
import com.aliyun.mns.client.CloudAccount;
import com.aliyun.mns.client.CloudQueue;
import com.aliyun.mns.client.MNSClient;
import com.aliyun.mns.model.Message;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@Servicepublic
class WXSyncService {
private final Logger logger = Logger.getLogger(WXSyncService.class);
private static MNSClient client = new CloudAccount("w0C4xyNgsq818Vnn", "56LcQF4JTXmSeXVdpv9MLzTBtLxGUP", "http://1989891155472375.mns.cn-hangzhou.aliyuncs.com").getMNSClient();
private static CloudQueue queue = client.getQueueRef("zhsync-v1");
public void sendMNS(HashMap msg) {
try {
Message message = new Message();
message.setMessageBody(JSON.toJSONString(msg));
Message putMsg = queue.putMessage(message);
logger.info(" --- Send MNS ---- " + msg + " --- mns id: " + putMsg.getMessageId());
} catch (Exception e) {
logger.info(" --- Send MNS ERROR --- " + msg + " --- error: " + e);
}
}
}
在 AdminShopController L328 (theOrderService.ShopPayQuick 和 L364 theOrderService.insertCashConsumption之后) 添加
try {
Member member = memberService.selectBymemberId(memberId);
HashMap<String, Object> map = new HashMap<>();
map.put("phone", member.getCellphone());
map.put("money", payMoney);
map.put("value", money);
map.put("type", "consume");
wxSyncService.sendMNS(map);
} catch (Exception e) {
//
}
TimerCount L120 (反储之后),添加
try {
Member member = memberService.selectBymemberId(memberId);
HashMap<String, Object> map = new HashMap<>();
map.put("phone", member.getCellphone());
map.put("money", valuePrice);
map.put("type", "back");
wxSyncService.sendMNS(map);
} catch (Exception e) {
//
}
网友评论