|
|
@@ -3,16 +3,19 @@ package com.uas.platform.b2c.common.weixin.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.platform.b2c.common.account.dao.UserDao;
|
|
|
+import com.uas.platform.b2c.common.account.model.Enterprise;
|
|
|
import com.uas.platform.b2c.common.account.model.User;
|
|
|
import com.uas.platform.b2c.common.weixin.model.MessageModel;
|
|
|
-import com.uas.platform.b2c.common.weixin.model.TemplateData;
|
|
|
+import com.uas.platform.b2c.common.weixin.model.TemplateDataDetail;
|
|
|
import com.uas.platform.b2c.common.weixin.model.TemplateMessage;
|
|
|
import com.uas.platform.b2c.common.weixin.service.WeChatService;
|
|
|
import com.uas.platform.b2c.common.weixin.util.WeChatUtil;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.sso.common.util.HttpUtil;
|
|
|
+import com.uas.sso.entity.UserAccount;
|
|
|
import com.uas.sso.entity.UserView;
|
|
|
import com.uas.sso.util.AccountUtils;
|
|
|
+import net.sf.json.JSONArray;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
@@ -20,6 +23,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* @author liusw
|
|
|
@@ -40,12 +44,32 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
result.put("headimgurl", userInfo.getString("headimgurl"));
|
|
|
String openid = userInfo.getString("openid");
|
|
|
result.put("openid", openid);
|
|
|
- // todo 检查当前用户是否绑定
|
|
|
- result.put("status", 0);
|
|
|
+ User user = userDao.findUsersByOpenId(openid);
|
|
|
+ if (StringUtils.isEmpty(user)) {
|
|
|
+ result.put("status", 0);
|
|
|
+ } else {
|
|
|
+ result.put("status", 1);
|
|
|
+ // 转成userAccount
|
|
|
+ UserAccount userAccount = convertUserAccount(user);
|
|
|
+ // 企业信息单独提出
|
|
|
+ Set<Enterprise> enterprises = user.getEnterprises();
|
|
|
+ result.put("userAccount", userAccount);
|
|
|
+ result.put("enterprises", enterprises);
|
|
|
+ }
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private UserAccount convertUserAccount(User user) {
|
|
|
+ UserAccount userAccount = new UserAccount();
|
|
|
+ userAccount.setAppId("mall");
|
|
|
+ userAccount.setVipName(user.getUserName());
|
|
|
+ userAccount.setEmail(user.getUserEmail());
|
|
|
+ userAccount.setMobile(user.getUserTel());
|
|
|
+ userAccount.setUserUU(user.getUserUU());
|
|
|
+ return userAccount;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ModelMap sendTemplateMessage(List<MessageModel> messages) {
|
|
|
ModelMap result = new ModelMap();
|
|
|
@@ -57,12 +81,22 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
JSONObject jsonObject = JSON.parseObject(res.getContent());
|
|
|
String access_token = jsonObject.getString("access_token");
|
|
|
String sendTemplateUrl = WeChatUtil.GET_ACCESS_TOKEN.replace("ACCESS_TOKEN", access_token);
|
|
|
+ // 模板内容设置
|
|
|
TemplateMessage templateMessage = new TemplateMessage();
|
|
|
templateMessage.setTemplateId(WeChatUtil.INQUIRY_TEMPLATE_ID);
|
|
|
+ templateMessage.setUrl("https://www.usoftmall.com/vendor#/seekPurchase");
|
|
|
+ TemplateDataDetail first = new TemplateDataDetail();
|
|
|
+ TemplateDataDetail remark = new TemplateDataDetail();
|
|
|
+ remark.setValue("快登陆优软商城查看详情吧!");
|
|
|
for (MessageModel messageModel : messages) {
|
|
|
User user= userDao.findOne(messageModel.getReceiverUu());
|
|
|
-// String jsonstr = array.toString();
|
|
|
-// HttpUtil.doPost(sendTemplateUrl, jsonstr);
|
|
|
+ if (!StringUtils.isEmpty(user.getOpenId())) {
|
|
|
+ templateMessage.setTouser(user.getOpenId());
|
|
|
+ first.setValue(messageModel.getContent());
|
|
|
+ JSONArray array = JSONArray.fromObject(templateMessage);
|
|
|
+ String jsonstr = array.toString();
|
|
|
+ HttpUtil.doPost(sendTemplateUrl, jsonstr);
|
|
|
+ }
|
|
|
}
|
|
|
result.put("success", true);
|
|
|
return result;
|
|
|
@@ -78,7 +112,7 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
public ModelMap bindUser(User user) {
|
|
|
ModelMap result = new ModelMap();
|
|
|
// 账户中心校验手机号和密码是否正确
|
|
|
- if (StringUtils.isEmpty(user) || StringUtils.isEmpty(user.getUserTel()) || StringUtils.isEmpty(user.getUserPwd())) {
|
|
|
+ if (StringUtils.isEmpty(user) || StringUtils.isEmpty(user.getUserTel()) || StringUtils.isEmpty(user.getUserPwd()) || StringUtils.isEmpty(user.getOpenId())) {
|
|
|
throw new IllegalOperatorException("信息不完整!");
|
|
|
}
|
|
|
// 是否存在用户信息
|
|
|
@@ -86,16 +120,31 @@ public class WeChatServiceImpl implements WeChatService{
|
|
|
if (CollectionUtils.isEmpty(oldUsers)) {
|
|
|
throw new IllegalOperatorException("未找到用户信息");
|
|
|
}
|
|
|
+ User judgeUser = userDao.findUsersByOpenId(user.getOpenId());
|
|
|
+ if (!StringUtils.isEmpty(judgeUser)) {
|
|
|
+ throw new IllegalOperatorException("该微信号已被绑定");
|
|
|
+ }
|
|
|
UserView userView = new UserView();
|
|
|
userView.setMobile(user.getUserTel());
|
|
|
userView.setPassword(user.getUserPwd());
|
|
|
boolean pass = false;
|
|
|
try {
|
|
|
+ User oldUser = oldUsers.get(0);
|
|
|
+ if (!StringUtils.isEmpty(oldUser.getOpenId())) {
|
|
|
+ throw new IllegalOperatorException("该用户已经绑定微信号");
|
|
|
+ }
|
|
|
pass = AccountUtils.fuzzyCheckPassword(userView);
|
|
|
if (!pass) {
|
|
|
throw new IllegalOperatorException("手机号或密码不正确");
|
|
|
}
|
|
|
- user = oldUsers.get(0);
|
|
|
+ oldUser.setOpenId(user.getOpenId());
|
|
|
+ user = userDao.save(oldUser);
|
|
|
+ // 转成UserAccount便于登录
|
|
|
+ UserAccount userAccount = convertUserAccount(user);
|
|
|
+ // 企业信息单独提出
|
|
|
+ Set<Enterprise> enterprises = user.getEnterprises();
|
|
|
+ result.put("userAccount", userAccount);
|
|
|
+ result.put("enterprises", enterprises);
|
|
|
result.put("success", true);
|
|
|
return result;
|
|
|
} catch (Exception e) {
|