package com.doumee.config.wx;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.core.constants.Constants;
|
import com.doumee.core.utils.DateUtil;
|
import com.doumee.core.utils.HttpsUtil;
|
import com.doumee.dao.business.model.IdentityInfo;
|
import lombok.extern.slf4j.Slf4j;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* Created by IntelliJ IDEA.
|
*
|
* @Author : Rk
|
* @create 2022/12/7 17:27
|
*/
|
@Service
|
@Slf4j
|
public class SendWxMessage {
|
|
|
private static String mineUrl = "/pages/mine/mine";
|
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
/**
|
* 信息认证
|
* @param openid
|
* @param identityInfo
|
* @throws WxErrorException
|
*/
|
public void identityInfoMessage(String openid, IdentityInfo identityInfo){
|
try{
|
|
String accessToken = WxMiniConfig.wxMaService.getAccessToken();
|
log.info("微信小程序->微信消息通知 - 认证信息 -> accessToken:{}",accessToken);
|
//这里简单起见我们每次都获取最新的access_token(时间开发中,应该在access_token快过期时再重新获取)
|
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+accessToken;
|
//拼接推送的模版
|
WxMsgVO wxMsgVO = new WxMsgVO();
|
//用户的openid(要发送给那个用户)
|
wxMsgVO.setTouser(openid);
|
//订阅消息模板id
|
wxMsgVO.setTemplate_id("VJho7-lf-4_WZFfOzenDnX6sOhYBJWwkLExVjBB563U");
|
Map<String, TemplateData> m = new HashMap<>(4);
|
m.put("thing2", new TemplateData(Constants.equalsInteger(identityInfo.getType(),Constants.ZERO)?"用工认证":Constants.equalsInteger(identityInfo.getType(),Constants.ONE)?"运货认证":"供餐认证"));
|
m.put("phrase6", new TemplateData(Constants.equalsInteger(identityInfo.getAuditStatus(),Constants.TWO)?"通过":"未通过"));
|
m.put("time12", new TemplateData(DateUtil.formatDate(identityInfo.getAuditTime(),"yyyy-MM-dd HH:mm")));
|
wxMsgVO.setPage(mineUrl);
|
wxMsgVO.setData(m);
|
log.error("微信小程序->微信消息通知 认证信息:{}", JSONObject.toJSONString(wxMsgVO));
|
String responseEntity = HttpsUtil.postJson(url,JSONObject.toJSONString(wxMsgVO));
|
log.error("微信小程序->微信消息通知 认证信息:{}", JSONObject.toJSONString(responseEntity));
|
}catch (WxErrorException wxErrorException){
|
|
}
|
}
|
|
}
|