dev-discount
parent
9a4128c17f
commit
ec305bc568
@ -0,0 +1,33 @@ |
|||||||
|
package com.hai.config; |
||||||
|
|
||||||
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
||||||
|
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
||||||
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
|
||||||
|
import javax.annotation.PostConstruct; |
||||||
|
|
||||||
|
@Configuration |
||||||
|
public class WxMaConfiguration { |
||||||
|
|
||||||
|
private static WxMaService maService; |
||||||
|
|
||||||
|
public static WxMaService getMaService() { |
||||||
|
if (maService == null) { |
||||||
|
throw new IllegalArgumentException(String.format("未找到对应的配置,请核实!")); |
||||||
|
} |
||||||
|
|
||||||
|
return maService; |
||||||
|
} |
||||||
|
|
||||||
|
@PostConstruct |
||||||
|
public void init() { |
||||||
|
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); |
||||||
|
config.setAppid(CommonSysConst.getSysConfig().getApiKey()); |
||||||
|
config.setSecret(CommonSysConst.getSysConfig().getApiSecret()); |
||||||
|
|
||||||
|
maService = new WxMaServiceImpl(); |
||||||
|
maService.setWxMaConfig(config); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,90 @@ |
|||||||
|
package com.hai.config; |
||||||
|
|
||||||
|
import cn.binarywang.wx.miniapp.api.WxMaMsgService; |
||||||
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; |
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaTemplateData; |
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.common.utils.DateUtil; |
||||||
|
import com.hai.common.utils.HttpsUtils; |
||||||
|
|
||||||
|
import com.hai.common.utils.ResponseMsgUtil; |
||||||
|
import com.hai.entity.HighChildOrder; |
||||||
|
import com.hai.entity.HighOrder; |
||||||
|
import com.hai.model.ResponseData; |
||||||
|
import com.hai.service.HighOrderService; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class WxMsgConfig { |
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(WxMsgConfig.class); |
||||||
|
|
||||||
|
@Resource |
||||||
|
private static HighOrderService highOrderService; |
||||||
|
|
||||||
|
|
||||||
|
public static ResponseData pushOneUser(Long orderId) { |
||||||
|
|
||||||
|
try { |
||||||
|
List<WxMaSubscribeMessage.Data> list = new ArrayList<>(); |
||||||
|
|
||||||
|
HighChildOrder highChildOrder = highOrderService.getChildOrderByPresentation(orderId); |
||||||
|
|
||||||
|
HighOrder highOrder = highOrderService.getOrderById(orderId); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, String> m = new HashMap<>(); |
||||||
|
m.put("thing1", highChildOrder.getGoodsName()); |
||||||
|
m.put("amount2", highChildOrder.getGoodsActualPrice() + "元"); |
||||||
|
m.put("character_string3", highOrder.getOrderNo()); |
||||||
|
m.put("time4", DateUtil.date2String(highOrder.getPayTime() , "yyyy年MM月dd天 HH分mm秒")); |
||||||
|
m.put("thing6", "微信支付"); |
||||||
|
|
||||||
|
for (String key: m.keySet()) { |
||||||
|
WxMaSubscribeMessage.Data msgElement = new WxMaSubscribeMessage.Data(); |
||||||
|
msgElement.setName(key); |
||||||
|
msgElement.setValue(m.get(key)); |
||||||
|
list.add(msgElement); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage(); |
||||||
|
subscribeMessage.setToUser("oUGn_4lkgegcjTc9oR1qBGjtAm3A"); // 小程序openId
|
||||||
|
subscribeMessage.setTemplateId("oUvaCPeeOg4wH6HTvCcSabU6FnzXUXOBXsqBYAPOV-U"); |
||||||
|
subscribeMessage.setData(list); |
||||||
|
subscribeMessage.setPage("pages/user/order_details/order_details?id=666"); |
||||||
|
subscribeMessage.setMiniprogramState("developer"); |
||||||
|
|
||||||
|
final WxMaService wxService = WxMaConfiguration.getMaService(); |
||||||
|
WxMaMsgService maMsgService = wxService.getMsgService(); |
||||||
|
maMsgService.sendSubscribeMsg(subscribeMessage); |
||||||
|
return ResponseMsgUtil.success("发送成功"); |
||||||
|
} catch (Exception e) { |
||||||
|
return ResponseMsgUtil.exception(e); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public static JSONObject getWxMsgToken() { |
||||||
|
|
||||||
|
Map<String, Object> map = new HashMap<>(); |
||||||
|
|
||||||
|
map.put("appid", CommonSysConst.getSysConfig().getApiKey()); |
||||||
|
map.put("secret", CommonSysConst.getSysConfig().getApiSecret()); |
||||||
|
map.put("grant_type", "client_credential"); |
||||||
|
|
||||||
|
return HttpsUtils.doGet(CommonSysConst.getSysConfig().getTokenUrl() + "/cgi-bin/token", map); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue