|
@@ -1,11 +1,23 @@
|
|
|
package com.ygj.yuemum.service.global;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.ygj.yuemum.dao.global.WeChatInfoDao;
|
|
|
+import com.ygj.yuemum.domain.customer.CustomerBooking;
|
|
|
+import com.ygj.yuemum.domain.global.TemplateData;
|
|
|
import com.ygj.yuemum.domain.global.WeChatInfo;
|
|
|
+import com.ygj.yuemum.domain.global.WechatTemplate;
|
|
|
import com.ygj.yuemum.domain.wxmini.WXUser;
|
|
|
import com.ygj.yuemum.service.wxmini.WXUserService;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
+import org.apache.http.HttpStatus;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.ContentType;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -16,6 +28,7 @@ import javax.crypto.NoSuchPaddingException;
|
|
|
import javax.crypto.spec.IvParameterSpec;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URL;
|
|
@@ -40,12 +53,17 @@ public class WeChatInfoService {
|
|
|
public static String MINIAPPID = "wx1c3ef3300b74ed86";
|
|
|
public static String MINIAPPSECRET = "ba5624bc087921d5a5832da9193e40f1";
|
|
|
|
|
|
-
|
|
|
public static String GRANT_TYPE = "client_credential";
|
|
|
public static String JSAPI_TICKET_TYPE = "jsapi";
|
|
|
public static String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token";
|
|
|
public static String JSAPI_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
|
|
|
public static String JSCODE2SESSION = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
+
|
|
|
+ public static String SENDMESSAGEURL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
|
|
|
+ public static String SENDOPENID = "oAjHTv9I4j1_D_BfIzBaj1bbYU9s";
|
|
|
+ public static String OrderTemplateid = "VyMPKDDGOy85wDIJuXR7sBuiIBEg0OPaCg6C_Dt_D0g";
|
|
|
+ public static String BookingTemplateid = "Wvysqh3Ec9lXpf5tytq0T2zzs662uowNLFCPiAPBFkA";
|
|
|
+
|
|
|
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
|
String access_Token;
|
|
|
String expires_in;
|
|
@@ -56,6 +74,124 @@ public class WeChatInfoService {
|
|
|
String session_key;
|
|
|
String openid;
|
|
|
|
|
|
+ public int WXSendOrderMessage(String orderno, String total, String date) throws IOException {
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ WechatTemplate wechatTemplate = new WechatTemplate();
|
|
|
+ wechatTemplate.setTemplate_id(OrderTemplateid);
|
|
|
+ wechatTemplate.setTouser(SENDOPENID);
|
|
|
+
|
|
|
+ Map<String,TemplateData> mapdata = new HashMap<>();
|
|
|
+ // 封装模板数据
|
|
|
+ TemplateData first = new TemplateData();
|
|
|
+ first.setValue("用户设备租赁单在线支付成功!");
|
|
|
+ first.setColor("#173177");
|
|
|
+ mapdata.put("first", first);
|
|
|
+
|
|
|
+ TemplateData keyword1 = new TemplateData();
|
|
|
+ keyword1.setValue(orderno);
|
|
|
+ keyword1.setColor("#fc6961");
|
|
|
+ mapdata.put("keyword1", keyword1);
|
|
|
+
|
|
|
+ TemplateData keyword2 = new TemplateData();
|
|
|
+ keyword2.setValue(total);
|
|
|
+ keyword2.setColor("#173177");
|
|
|
+ mapdata.put("keyword2", keyword2);
|
|
|
+
|
|
|
+ TemplateData keyword3 = new TemplateData();
|
|
|
+ keyword3.setValue(date);
|
|
|
+ keyword3.setColor("#173177");
|
|
|
+ mapdata.put("keyword3", keyword3);
|
|
|
+
|
|
|
+ TemplateData keyword5 = new TemplateData();
|
|
|
+ keyword5.setValue("请尽快完善订单及时发货");
|
|
|
+ keyword5.setColor("#173177");
|
|
|
+ mapdata.put("remark", keyword5);
|
|
|
+
|
|
|
+ wechatTemplate.setData(mapdata);
|
|
|
+ String toString = mapper.writeValueAsString(wechatTemplate);
|
|
|
+ String result = "";
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ WeChatInfo weChatInfo = weChatInfoDao.getWeChatInfo();
|
|
|
+ HttpPost httpPost = new HttpPost(SENDMESSAGEURL+weChatInfo.getAccess_token());
|
|
|
+ StringEntity stringEntity = new StringEntity(toString, ContentType.APPLICATION_JSON);
|
|
|
+ stringEntity.setContentEncoding("utf-8");
|
|
|
+ httpPost.setEntity(stringEntity);
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
|
+ result = EntityUtils.toString(response.getEntity(), "utf-8");
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ public int WXSendBookingMessage(CustomerBooking customerBooking) throws IOException {
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ WechatTemplate wechatTemplate = new WechatTemplate();
|
|
|
+ wechatTemplate.setTemplate_id(BookingTemplateid);
|
|
|
+ wechatTemplate.setTouser(SENDOPENID);
|
|
|
+
|
|
|
+ Map<String,TemplateData> mapdata = new HashMap<>();
|
|
|
+ // 封装模板数据
|
|
|
+ TemplateData first = new TemplateData();
|
|
|
+ first.setValue("用户发送预约信息!");
|
|
|
+ first.setColor("#173177");
|
|
|
+ mapdata.put("first", first);
|
|
|
+
|
|
|
+ TemplateData keyword2 = new TemplateData();
|
|
|
+ keyword2.setValue(customerBooking.getBk_phone());
|
|
|
+ keyword2.setColor("#fc6961");
|
|
|
+ mapdata.put("keyword2", keyword2);
|
|
|
+
|
|
|
+ TemplateData keyword3 = new TemplateData();
|
|
|
+ keyword3.setValue(customerBooking.getBk_date());
|
|
|
+ keyword3.setColor("#173177");
|
|
|
+ mapdata.put("keyword3", keyword3);
|
|
|
+ if(customerBooking.getBk_type().equals(1)){
|
|
|
+ TemplateData keyword4 = new TemplateData();
|
|
|
+ keyword4.setValue("套餐预约,套餐名称:"+customerBooking.getBk_desc());
|
|
|
+ keyword4.setColor("#173177");
|
|
|
+ mapdata.put("keyword4", keyword4);
|
|
|
+ }
|
|
|
+ if(customerBooking.getBk_type().equals(4)){
|
|
|
+ TemplateData keyword4 = new TemplateData();
|
|
|
+ keyword4.setValue("顾问预约,"+"预产期:"+customerBooking.getBk_duedate());
|
|
|
+ keyword4.setColor("#173177");
|
|
|
+ mapdata.put("keyword4", keyword4);
|
|
|
+ }
|
|
|
+ if(customerBooking.getBk_type().equals(5)){
|
|
|
+ TemplateData keyword4 = new TemplateData();
|
|
|
+ keyword4.setValue("设备返还预约,租赁单编号:"+customerBooking.getBk_desc());
|
|
|
+ keyword4.setColor("#173177");
|
|
|
+ mapdata.put("keyword4", keyword4);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ TemplateData keyword5 = new TemplateData();
|
|
|
+ keyword5.setValue("请尽快安排顾问跟进!");
|
|
|
+ keyword5.setColor("#173177");
|
|
|
+ mapdata.put("remark", keyword5);
|
|
|
+
|
|
|
+ wechatTemplate.setData(mapdata);
|
|
|
+ String toString = mapper.writeValueAsString(wechatTemplate);
|
|
|
+ System.out.println(toString);
|
|
|
+
|
|
|
+ String result = "";
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ WeChatInfo weChatInfo = weChatInfoDao.getWeChatInfo();
|
|
|
+ HttpPost httpPost = new HttpPost(SENDMESSAGEURL+weChatInfo.getAccess_token());
|
|
|
+ StringEntity stringEntity = new StringEntity(toString, ContentType.APPLICATION_JSON);
|
|
|
+ stringEntity.setContentEncoding("utf-8");
|
|
|
+ httpPost.setEntity(stringEntity);
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
|
+ result = EntityUtils.toString(response.getEntity(), "utf-8");
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ System.out.println(result);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
public int SaveWeChatInfo() {
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
try {
|