|
@@ -12,9 +12,11 @@ import com.ygj.yuemum.domain.global.MiniAppInfo;
|
|
|
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.WXPublic;
|
|
|
import com.ygj.yuemum.domain.wxmini.WXUser;
|
|
|
import com.ygj.yuemum.service.distributionchannel.DcIntroduceLogService;
|
|
|
import com.ygj.yuemum.service.distributionchannel.DcIntroducerService;
|
|
|
+import com.ygj.yuemum.service.wxmini.WXPublicService;
|
|
|
import com.ygj.yuemum.service.wxmini.WXUserService;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.http.HttpStatus;
|
|
@@ -25,6 +27,7 @@ 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.omg.PortableInterceptor.INACTIVE;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -57,6 +60,8 @@ public class WeChatInfoService {
|
|
|
private DcIntroduceLogService dcIntroduceLogService;
|
|
|
@Autowired
|
|
|
private DcIntroducerService dcIntroducerService;
|
|
|
+ @Autowired
|
|
|
+ private WXPublicService wxPublicService;
|
|
|
public String APPID = Constant.APPID;
|
|
|
public String APPSECRET = Constant.APPSECRET;
|
|
|
public String MINIAPPID = Constant.MINIAPPID;
|
|
@@ -76,19 +81,13 @@ public class WeChatInfoService {
|
|
|
String access_Token;
|
|
|
String expires_in;
|
|
|
String jsapi_Ticket;
|
|
|
- String noncestr;
|
|
|
- String timeStamp;
|
|
|
- String signaTure;
|
|
|
String session_key;
|
|
|
String openid;
|
|
|
|
|
|
- public int WXSendExtractMessage(String wue_applysum, String wue_phone, String wue_bank_card,String wue_account_name) throws IOException {
|
|
|
+ public int WXSendExtractMessage(String wue_applysum, String wue_phone, String wue_bank_card, String wue_account_name) throws IOException {
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
-// String resultToken = sendGet("http://yuesuo.yueguanjia.com/modoo-1/getWxPublicSender");
|
|
|
-// Map mapToken = JSON.parseObject(resultToken);
|
|
|
-// String openid = String.valueOf(mapToken.get("wp_openid"));
|
|
|
- Map<String,TemplateData> mapdata = new HashMap<>();
|
|
|
+ Map<String, TemplateData> mapdata = new HashMap<>();
|
|
|
|
|
|
WechatTemplate wechatTemplate = new WechatTemplate();
|
|
|
wechatTemplate.setTemplate_id(ExtractTemplateid);
|
|
@@ -110,7 +109,7 @@ public class WeChatInfoService {
|
|
|
mapdata.put("keyword2", keyword2);
|
|
|
|
|
|
TemplateData keyword5 = new TemplateData();
|
|
|
- keyword5.setValue("手机号:" +wue_phone+ ",收款人:"+wue_account_name+",银行卡号:" +wue_bank_card+"。请尽快处理!");
|
|
|
+ keyword5.setValue("手机号:" + wue_phone + ",收款人:" + wue_account_name + ",银行卡号:" + wue_bank_card + "。请尽快处理!");
|
|
|
keyword5.setColor("#173177");
|
|
|
mapdata.put("remark", keyword5);
|
|
|
|
|
@@ -120,7 +119,7 @@ public class WeChatInfoService {
|
|
|
String result = "";
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
WeChatInfo weChatInfo = weChatInfoDao.getWeChatInfo();
|
|
|
- HttpPost httpPost = new HttpPost(SENDMESSAGEURL+weChatInfo.getAccess_token());
|
|
|
+ HttpPost httpPost = new HttpPost(SENDMESSAGEURL + weChatInfo.getAccess_token());
|
|
|
StringEntity stringEntity = new StringEntity(toString, ContentType.APPLICATION_JSON);
|
|
|
stringEntity.setContentEncoding("utf-8");
|
|
|
httpPost.setEntity(stringEntity);
|
|
@@ -135,11 +134,7 @@ public class WeChatInfoService {
|
|
|
|
|
|
public int WXSendOrderMessage(String orderno, String total, String date) throws IOException {
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
-
|
|
|
-// String resultToken = sendGet("http://yuesuo.yueguanjia.com/modoo-1/getWxPublicSender");
|
|
|
-// Map mapToken = JSON.parseObject(resultToken);
|
|
|
-// String openid = String.valueOf(mapToken.get("wp_openid"));
|
|
|
- Map<String,TemplateData> mapdata = new HashMap<>();
|
|
|
+ Map<String, TemplateData> mapdata = new HashMap<>();
|
|
|
|
|
|
WechatTemplate wechatTemplate = new WechatTemplate();
|
|
|
wechatTemplate.setTemplate_id(OrderTemplateid);
|
|
@@ -175,7 +170,7 @@ public class WeChatInfoService {
|
|
|
String result = "";
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
WeChatInfo weChatInfo = weChatInfoDao.getWeChatInfo();
|
|
|
- HttpPost httpPost = new HttpPost(SENDMESSAGEURL+weChatInfo.getAccess_token());
|
|
|
+ HttpPost httpPost = new HttpPost(SENDMESSAGEURL + weChatInfo.getAccess_token());
|
|
|
StringEntity stringEntity = new StringEntity(toString, ContentType.APPLICATION_JSON);
|
|
|
stringEntity.setContentEncoding("utf-8");
|
|
|
httpPost.setEntity(stringEntity);
|
|
@@ -188,17 +183,9 @@ public class WeChatInfoService {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
- public int WXSendYSOrderMessage(String orderno, String total, String date,String type) throws IOException {
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
-
|
|
|
-// String resultToken = sendGet("http://yuesuo.yueguanjia.com/modoo-1/getWxPublicSender");
|
|
|
-// Map mapToken = JSON.parseObject(resultToken);
|
|
|
-// String openid = String.valueOf(mapToken.get("wp_openid"));
|
|
|
- Map<String,TemplateData> mapdata = new HashMap<>();
|
|
|
-
|
|
|
+ public int WXSendYSOrderMessage(String orderNo, Integer od_cityID,String total, String date, String type) {
|
|
|
+ Map<String, TemplateData> mapdata = new HashMap<>();
|
|
|
WechatTemplate wechatTemplate = new WechatTemplate();
|
|
|
- wechatTemplate.setTemplate_id(OrderTemplateid);
|
|
|
- wechatTemplate.setTouser(WPOPENID);
|
|
|
// 封装模板数据
|
|
|
TemplateData first = new TemplateData();
|
|
|
if (type.equals("2")) {
|
|
@@ -209,124 +196,121 @@ public class WeChatInfoService {
|
|
|
first.setColor("#173177");
|
|
|
}
|
|
|
mapdata.put("first", first);
|
|
|
-
|
|
|
TemplateData keyword1 = new TemplateData();
|
|
|
- keyword1.setValue(orderno);
|
|
|
+ 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 {
|
|
|
+ wechatTemplate.setTemplate_id(OrderTemplateid);
|
|
|
+ try {
|
|
|
+ sendAction(wechatTemplate,mapdata,od_cityID);
|
|
|
+ }catch (Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
return 0;
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public int WXSendBookingMessage(CustomerBooking customerBooking) throws IOException {
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
-// String resultToken = sendGet("http://yuesuo.yueguanjia.com/modoo-1/getWxPublicSender");
|
|
|
-// Map mapToken = JSON.parseObject(resultToken);
|
|
|
-// String openid = String.valueOf(mapToken.get("wp_openid"));
|
|
|
+ public int WXSendBookingMessage(CustomerBooking customerBooking) {
|
|
|
WechatTemplate wechatTemplate = new WechatTemplate();
|
|
|
- wechatTemplate.setTemplate_id(BookingTemplateid);
|
|
|
- wechatTemplate.setTouser(WPOPENID);
|
|
|
-
|
|
|
- Map<String,TemplateData> mapdata = new HashMap<>();
|
|
|
+ Map<String, TemplateData> mapData = new HashMap<>();
|
|
|
// 封装模板数据
|
|
|
TemplateData first = new TemplateData();
|
|
|
- if(customerBooking.getBk_type().equals(4) && customerBooking.getBk_introducer_phone() != null && customerBooking.getBk_introducer_phone() != ""){
|
|
|
- first.setValue("顾问预约信息!介绍人手机:"+customerBooking.getBk_introducer_phone()+",介绍人顾问:"+customerBooking.getBk_introducer_consultant()+"!");
|
|
|
+ if (customerBooking.getBk_type().equals(4) && customerBooking.getBk_introducer_phone() != null && customerBooking.getBk_introducer_phone() != "") {
|
|
|
+ first.setValue("顾问预约信息!介绍人手机:" + customerBooking.getBk_introducer_phone() + ",介绍人顾问:" + customerBooking.getBk_introducer_consultant() + "!");
|
|
|
first.setColor("#173177");
|
|
|
- } else if(customerBooking.getBk_type().equals(1) && customerBooking.getBk_introducer_phone() != null && customerBooking.getBk_introducer_phone() != "") {
|
|
|
- first.setValue("套餐预约信息!介绍人手机:"+customerBooking.getBk_introducer_phone()+",介绍人顾问:"+customerBooking.getBk_introducer_consultant()+"!");
|
|
|
+ } else if (customerBooking.getBk_type().equals(1) && customerBooking.getBk_introducer_phone() != null && customerBooking.getBk_introducer_phone() != "") {
|
|
|
+ first.setValue("套餐预约信息!介绍人手机:" + customerBooking.getBk_introducer_phone() + ",介绍人顾问:" + customerBooking.getBk_introducer_consultant() + "!");
|
|
|
first.setColor("#173177");
|
|
|
} else {
|
|
|
first.setValue("预约信息!");
|
|
|
first.setColor("#173177");
|
|
|
}
|
|
|
-
|
|
|
- mapdata.put("first", first);
|
|
|
-
|
|
|
+ mapData.put("first", first);
|
|
|
TemplateData keyword2 = new TemplateData();
|
|
|
keyword2.setValue(customerBooking.getBk_phone());
|
|
|
keyword2.setColor("#fc6961");
|
|
|
- mapdata.put("keyword2", keyword2);
|
|
|
-
|
|
|
+ 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)){
|
|
|
+ mapData.put("keyword3", keyword3);
|
|
|
+ if (customerBooking.getBk_type().equals(1)) {
|
|
|
TemplateData keyword4 = new TemplateData();
|
|
|
- keyword4.setValue("套餐预约,套餐名称:"+customerBooking.getBk_desc());
|
|
|
+ keyword4.setValue("套餐预约,套餐名称:" + customerBooking.getBk_desc());
|
|
|
keyword4.setColor("#173177");
|
|
|
- mapdata.put("keyword4", keyword4);
|
|
|
+ mapData.put("keyword4", keyword4);
|
|
|
}
|
|
|
- if(customerBooking.getBk_type().equals(4)){
|
|
|
+ if (customerBooking.getBk_type().equals(4)) {
|
|
|
TemplateData keyword4 = new TemplateData();
|
|
|
- keyword4.setValue("顾问预约,"+"预产期:"+customerBooking.getBk_duedate());
|
|
|
+ keyword4.setValue("顾问预约," + "预产期:" + customerBooking.getBk_duedate());
|
|
|
keyword4.setColor("#173177");
|
|
|
- mapdata.put("keyword4", keyword4);
|
|
|
+ mapData.put("keyword4", keyword4);
|
|
|
}
|
|
|
- if(customerBooking.getBk_type().equals(5)){
|
|
|
+ if (customerBooking.getBk_type().equals(5)) {
|
|
|
TemplateData keyword4 = new TemplateData();
|
|
|
- keyword4.setValue("设备返还预约,租赁单编号:"+customerBooking.getBk_desc());
|
|
|
+ keyword4.setValue("设备返还预约,租赁单编号:" + customerBooking.getBk_desc());
|
|
|
keyword4.setColor("#173177");
|
|
|
- mapdata.put("keyword4", keyword4);
|
|
|
+ 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);
|
|
|
+ mapData.put("remark", keyword5);
|
|
|
+ wechatTemplate.setTemplate_id(BookingTemplateid);
|
|
|
|
|
|
- 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 {
|
|
|
+ try {
|
|
|
+ sendAction(wechatTemplate,mapData,customerBooking.getBk_branches_id());
|
|
|
+ }catch (Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
return 0;
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+ public int sendAction(WechatTemplate wechatTemplate,Map<String, TemplateData> mapdata, Integer od_cityid) {
|
|
|
+ try {
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ List<WXPublic> wxPublics = wxPublicService.getOpenidsByCityCode(od_cityid);
|
|
|
+ for (WXPublic wxPublic : wxPublics) {
|
|
|
+ wechatTemplate.setTouser(wxPublic.getWp_openid());
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
public int SaveWeChatInfo() {
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
try {
|
|
@@ -383,23 +367,23 @@ public class WeChatInfoService {
|
|
|
//检查用户是否已经注册,注册返回手机号等信息,没注册返回openid作为用户名
|
|
|
//新用户 insert ,没有手机返回openid 有手机返回手机号等信息
|
|
|
WXUser ckeckwxUser = wxUserService.getWXUser(openid);
|
|
|
- if(ckeckwxUser != null) {
|
|
|
+ if (ckeckwxUser != null) {
|
|
|
result.put("openid", openid);
|
|
|
- result.put("type","2");
|
|
|
- result.put("nickName",ckeckwxUser.getXu_name());
|
|
|
- result.put("phone",ckeckwxUser.getXu_phone());
|
|
|
+ result.put("type", "2");
|
|
|
+ result.put("nickName", ckeckwxUser.getXu_name());
|
|
|
+ result.put("phone", ckeckwxUser.getXu_phone());
|
|
|
} else {
|
|
|
WXUser wxUser = new WXUser();
|
|
|
wxUser.setXu_openid(openid);
|
|
|
wxUser.setXu_sessionkey(session_key);
|
|
|
- UUID id=UUID.randomUUID();
|
|
|
- String[] idd=id.toString().split("-");
|
|
|
- String lsid = "YSLS"+idd[1];
|
|
|
+ UUID id = UUID.randomUUID();
|
|
|
+ String[] idd = id.toString().split("-");
|
|
|
+ String lsid = "YSLS" + idd[1];
|
|
|
wxUser.setXu_name(lsid);
|
|
|
wxUserService.insertWXUser(wxUser);
|
|
|
result.put("openid", openid);
|
|
|
- result.put("type","1");
|
|
|
- result.put("nickName",lsid);
|
|
|
+ result.put("type", "1");
|
|
|
+ result.put("nickName", lsid);
|
|
|
|
|
|
}
|
|
|
//介绍人介绍用户+1 多码存多条
|
|
@@ -407,13 +391,13 @@ public class WeChatInfoService {
|
|
|
dcIntroduceLog.setXul_introducer_phone(introducer);
|
|
|
dcIntroduceLog.setXul_event(0);
|
|
|
dcIntroduceLog.setXul_openid(openid);
|
|
|
- if (introducer != null && !introducer.equals("null") && introducer != "" && introducer != " ") {
|
|
|
+ if (introducer != null && !introducer.equals("null") && introducer != "" && introducer != " ") {
|
|
|
int filstCheck = dcIntroduceLogService.checkFirstDILogs(dcIntroduceLog);
|
|
|
- if (filstCheck ==0) {
|
|
|
+ if (filstCheck == 0) {
|
|
|
DcIntroducer dcIntroducer = dcIntroducerService.checkDcIntroducers(introducer);
|
|
|
if (dcIntroducer != null) {
|
|
|
// 介绍人注册用户+1
|
|
|
- dcIntroducer.setWv_people_count(dcIntroducer.getWv_people_count() + 1 );
|
|
|
+ dcIntroducer.setWv_people_count(dcIntroducer.getWv_people_count() + 1);
|
|
|
dcIntroducerService.updateDcIntroducer(dcIntroducer);
|
|
|
//log 记录
|
|
|
dcIntroduceLogService.insertDcIntroduceLog(dcIntroduceLog);
|
|
@@ -522,17 +506,19 @@ public class WeChatInfoService {
|
|
|
}
|
|
|
return jsonStr.toString();
|
|
|
}
|
|
|
- public String getWxDecrypt(String encrypdata,String ivdata, String openid) {
|
|
|
+
|
|
|
+ public String getWxDecrypt(String encrypdata, String ivdata, String openid) {
|
|
|
WXUser wxUser = wxUserService.getWXUser(openid);
|
|
|
- String str="undefined";
|
|
|
+ String str = "undefined";
|
|
|
try {
|
|
|
- str = decrypt(encrypdata,wxUser.getXu_sessionkey(),ivdata,"UTF-8");
|
|
|
+ str = decrypt(encrypdata, wxUser.getXu_sessionkey(), ivdata, "UTF-8");
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("解析手机号错误!");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return str;
|
|
|
}
|
|
|
+
|
|
|
public static String decrypt(String data, String key, String iv, String encodingFormat) throws Exception {
|
|
|
// initialize();
|
|
|
|