|
@@ -0,0 +1,215 @@
|
|
|
+package com.iamberry.rst.utils;
|
|
|
+
|
|
|
+import com.iamberry.wechat.tools.NameUtils;
|
|
|
+import com.iamberry.wechat.tools.ResultInfo;
|
|
|
+import com.iamberry.wechat.tools.WeixinUtil;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class SendMessageUtil {
|
|
|
+
|
|
|
+ //快递公司列表
|
|
|
+ public static HashMap<String, String> hashmap = new HashMap<String, String>();
|
|
|
+ //正式环境
|
|
|
+ {
|
|
|
+ hashmap.put("sto", "申通快递");
|
|
|
+ hashmap.put("yto", "圆通快递");
|
|
|
+ hashmap.put("sf", "顺丰快递");
|
|
|
+ hashmap.put("longbanwuliu", "龙邦快递");
|
|
|
+ hashmap.put("ems", "邮政EMS");
|
|
|
+ hashmap.put("zto", "中通快递");
|
|
|
+ hashmap.put("zjs", "宅急送");
|
|
|
+ hashmap.put("yunda", "韵达快递");
|
|
|
+ hashmap.put("cces", "cces快递");
|
|
|
+ hashmap.put("pick", "上门提货");
|
|
|
+ hashmap.put("htky", "汇通快递");
|
|
|
+ hashmap.put("ttkdex", "天天快递");
|
|
|
+ hashmap.put("stars", "邮政EMS");
|
|
|
+ hashmap.put("jd", "星晨急便");
|
|
|
+ hashmap.put("01", "其他");
|
|
|
+ hashmap.put("02", "上门送货");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送模板通知给用户
|
|
|
+ * @param date data 日期
|
|
|
+ * @param openId 接受的用户id
|
|
|
+ * @param url 点击打开的url
|
|
|
+ * @param type 发送类型 1,收益成功通知 2,发货提醒通知 3、收入提醒通知,4、订单未支付通知 5、试用进度提醒
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean sendTemplateMessageToOpenid(String date,String openId, String url,Integer type) {
|
|
|
+ boolean result = false;
|
|
|
+ switch (type) {
|
|
|
+ case 1: //1,收益成功通知
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId,ResultInfo.rewards_template_id, date, url);
|
|
|
+ break;
|
|
|
+ case 2: // 2,发货提醒通知
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.Shipment_template_id, date, url);
|
|
|
+ break;
|
|
|
+ case 3: //3、收入提醒通知
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.Income_template_id, date, url);
|
|
|
+ break;
|
|
|
+ case 4: //4、订单未支付通知
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.Order_template_id, date, url);
|
|
|
+ break;
|
|
|
+ case 5: //5、试用进度提醒
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.trial_progress_remind, date, url);
|
|
|
+ break;
|
|
|
+ case 6: //6、试用申请通知
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_apply_notice, date, url);
|
|
|
+ break;
|
|
|
+ case 7: //7、试用申请成功通知
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_apply_success, date, url);
|
|
|
+ break;
|
|
|
+ case 8: //8、订单支付成功
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_pay_success, date, url);
|
|
|
+ break;
|
|
|
+ case 9: //9、订单关闭成功
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_shut_down, date, url);
|
|
|
+ break;
|
|
|
+ case 10: //10、奖品领取通知
|
|
|
+ WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.prize_receive_push, date, url);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ result = true;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String date = "{'first':{'color':'#173177', 'value':'尊敬的客户您好~您的订单已发货~'}, 'order_id':{'color':'#173177','value':'1009145345B11792L'}, 'package_id':{'color':'#173177','value':'yuantong:34234234'}, 'remark':{'color':'#173177', 'value':'点击进入商城查看-->>'}}";
|
|
|
+ String openId = "o-icas0dRzE7WYAEAmcX4BQCUyFo";
|
|
|
+ String appId = "wxd995fb95b97ece1b";// 应用ID
|
|
|
+ String appSecret = "34922854462fba23cf54ce859349fcf4";// 应用密钥
|
|
|
+
|
|
|
+ WeixinUtil.sendTemplateMessage(appId, appSecret, openId, "744KA1PdB1I5PzRcjtxqbEz5t2bp8vdsi4I2ytW1rbE", date, "xx");
|
|
|
+ System.out.println("发送成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 试用进度提醒推送
|
|
|
+ * @param first 标题
|
|
|
+ * @param keyword1 商品名称
|
|
|
+ * @param keyword2 订单编号
|
|
|
+ * @param keyword3 申请时间
|
|
|
+ * @param keyword4 截止时间
|
|
|
+ * @param remark 全部内容
|
|
|
+ * @param openId 用户openid
|
|
|
+ * @param url 地址
|
|
|
+ */
|
|
|
+ public void probationPush(String first,String keyword1,String keyword2,String keyword3,String keyword4,String remark,String openId,String url){
|
|
|
+ String temp = ResultInfo.PROBATIONPUSH;
|
|
|
+ temp = temp.replaceFirst("firstValueIamberry", first)
|
|
|
+ .replaceFirst("keyword1Value",keyword1)
|
|
|
+ .replaceFirst("keyword2Value",keyword2)
|
|
|
+ .replaceFirst("keyword3Value",keyword3)
|
|
|
+ .replaceFirst("keyword4Value",keyword4)
|
|
|
+ .replaceFirst("remarkValue",remark);
|
|
|
+ sendTemplateMessageToOpenid(temp, openId, url,5);
|
|
|
+ temp = ResultInfo.PROBATIONPUSH;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 试用开始通知
|
|
|
+ * @param first 标题
|
|
|
+ * @param keyword1 商品信息
|
|
|
+ * @param keyword2 申请时间
|
|
|
+ * @param remark 全部内容
|
|
|
+ * @param openId 用户openid
|
|
|
+ * @param url 地址
|
|
|
+ */
|
|
|
+ public void probationApplyNotice(String first,String keyword1,String keyword2,String remark,String openId,String url){
|
|
|
+ String temp = ResultInfo.PROBATIONAPPLYNOTICE;
|
|
|
+ temp = temp.replaceFirst("firstValueIamberry", first)
|
|
|
+ .replaceFirst("keyword1Value",keyword1)
|
|
|
+ .replaceFirst("keyword2Value",keyword2)
|
|
|
+ .replaceFirst("remarkValue",remark);
|
|
|
+ sendTemplateMessageToOpenid(temp, openId, url,6);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 派送成功通知
|
|
|
+ * @param first 标题
|
|
|
+ * @param keyword1 申请单号
|
|
|
+ * @param keyword2 申请时间
|
|
|
+ * @param keyword3 应付金额
|
|
|
+ * @param keyword4 应付积分
|
|
|
+ * @param keyword5 支付方式
|
|
|
+ * @param remark 全部内容
|
|
|
+ * @param openId 用户openid
|
|
|
+ * @param url 地址
|
|
|
+ */
|
|
|
+ public void probationApplySuccess(String first,String keyword1,String keyword2,String keyword3,String keyword4,String keyword5,String remark,String openId,String url){
|
|
|
+ String temp = ResultInfo.PROBATIONAPPLYSUCCESS;
|
|
|
+ temp = temp.replaceFirst("firstValueIamberry", first)
|
|
|
+ .replaceFirst("keyword1Value",keyword1)
|
|
|
+ .replaceFirst("keyword2Value",keyword2)
|
|
|
+ .replaceFirst("keyword3Value",keyword3)
|
|
|
+ .replaceFirst("keyword4Value",keyword4)
|
|
|
+ .replaceFirst("keyword5Value",keyword5)
|
|
|
+ .replaceFirst("remarkValue",remark);
|
|
|
+ sendTemplateMessageToOpenid(temp, openId, url,7);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 试用订单支付成功
|
|
|
+ * @param first 标题
|
|
|
+ * @param keyword1 支付金额
|
|
|
+ * @param keyword2 商品信息
|
|
|
+ * @param remark 全部内容
|
|
|
+ * @param openId 用户openid
|
|
|
+ * @param url 地址
|
|
|
+ */
|
|
|
+ public void probationPaySuccess(String first,String keyword1,String keyword2,String remark,String openId,String url){
|
|
|
+ String temp = ResultInfo.PROBATIONPAYSUCCESS;
|
|
|
+ temp = temp.replaceFirst("firstValueIamberry", first)
|
|
|
+ .replaceFirst("orderMoneySumValue",keyword1)
|
|
|
+ .replaceFirst("orderProductNameValue",keyword2)
|
|
|
+ .replaceFirst("remarkValue",remark);
|
|
|
+ sendTemplateMessageToOpenid(temp, openId, url,8);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 试用订单关闭成功
|
|
|
+ * @param first 标题
|
|
|
+ * @param keyword1 支付金额
|
|
|
+ * @param keyword2 商品信息
|
|
|
+ * @param remark 全部内容
|
|
|
+ * @param openId 用户openid
|
|
|
+ * @param url 地址
|
|
|
+ */
|
|
|
+ public void probationShutDown(String first,String transid,String fee,String pay_time,String remark,String openId,String url){
|
|
|
+ String temp = ResultInfo.PROBATIONSHUTDOWN;
|
|
|
+ temp = temp.replaceFirst("firstValueIamberry", first)
|
|
|
+ .replaceFirst("transidValue",transid)
|
|
|
+ .replaceFirst("feeValue",fee)
|
|
|
+ .replaceFirst("pay_timeValue",pay_time)
|
|
|
+ .replaceFirst("remarkValue",remark);
|
|
|
+ sendTemplateMessageToOpenid(temp, openId, url,9);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推荐人领取通知
|
|
|
+ * @param first 标题
|
|
|
+ * @param keyword1 被推荐人
|
|
|
+ * @param keyword2 消费商家
|
|
|
+ * @param keyword3 消费金额
|
|
|
+ * @param keyword4 消费时间
|
|
|
+ * @param keyword4 推荐奖励
|
|
|
+ * @param remark 全部内容
|
|
|
+ * @param openId 用户openid
|
|
|
+ * @param url 跳转地址
|
|
|
+ */
|
|
|
+ public void prizeReceivePush(String first,String keyword1,String keyword2,String keyword3,String keyword4,String keyword5,String remark,String openId,String url){
|
|
|
+ String temp = ResultInfo.PRIZERECEIVEPUSH;
|
|
|
+ temp = temp.replaceFirst("firstValueIamberry", first)
|
|
|
+ .replaceFirst("keyword1Value",keyword1)
|
|
|
+ .replaceFirst("keyword2Value",keyword2)
|
|
|
+ .replaceFirst("keyword3Value",keyword3)
|
|
|
+ .replaceFirst("keyword4Value",keyword4)
|
|
|
+ .replaceFirst("keyword5Value",keyword5)
|
|
|
+ .replaceFirst("remarkValue",remark);
|
|
|
+ sendTemplateMessageToOpenid(temp, openId, url,10);
|
|
|
+ }
|
|
|
+}
|