Commit 2ddadc35 by 张新旗

修复bug中

parent c57c1a45
...@@ -3,14 +3,11 @@ package com.soss.web.controller.coffee; ...@@ -3,14 +3,11 @@ package com.soss.web.controller.coffee;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.soss.common.constant.Constants; import com.soss.common.constant.Constants;
import com.soss.common.core.domain.AjaxResult; import com.soss.common.core.domain.AjaxResult;
import com.soss.common.utils.spring.SpringUtils;
import com.soss.framework.web.service.WeixinServiceImpl; import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.domain.Order;
import com.soss.system.mapper.OrderMapper; import com.soss.system.mapper.OrderMapper;
import com.soss.system.service.impl.AppServiceImpl; import com.soss.system.service.impl.AppServiceImpl;
import com.soss.system.service.impl.OrderServiceImpl; import com.soss.system.service.impl.OrderServiceImpl;
import com.soss.system.service.impl.OrderTakingServiceImpl; import com.soss.system.service.impl.OrderTakingServiceImpl;
import com.soss.system.weixin.util.SendMessageUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -40,15 +37,25 @@ public class WeixinController { ...@@ -40,15 +37,25 @@ public class WeixinController {
public AjaxResult login(@RequestBody String body){ public AjaxResult login(@RequestBody String body){
JSONObject param = JSONObject.parseObject(body); JSONObject param = JSONObject.parseObject(body);
String code =param.getString("code"); String code =param.getString("code");
return AjaxResult.success(weixinService.login(code));
}
@PostMapping("/decrypt")
public AjaxResult decrypt(@RequestBody String body){
JSONObject param = JSONObject.parseObject(body);
String encryptedData = param.getString("encryptedData"); String encryptedData = param.getString("encryptedData");
String iv = param.getString("iv"); String iv = param.getString("iv");
String source = param.getString("source"); String source = param.getString("source");
String openId = param.getString("openId");
String sessionKey = param.getString("session_key");
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
Map<String,String> map = weixinService.login(code,encryptedData,iv,source); Map<String, String> decrypt = weixinService.decrypt(encryptedData, iv, source, openId, sessionKey);
ajax.put(Constants.TOKEN, map.get("token")); ajax.put(Constants.TOKEN, decrypt.get("token"));
ajax.put("phoneNumber", map.get("phoneNumber")); ajax.put("phoneNumber", decrypt.get("phoneNumber"));
ajax.put("customerName",map.get("customerName")); ajax.put("customerName",decrypt.get("customerName"));
return ajax; return ajax;
} }
@PostMapping("/refreshToken") @PostMapping("/refreshToken")
public AjaxResult getRefreshToken(@RequestBody String body){ public AjaxResult getRefreshToken(@RequestBody String body){
......
...@@ -159,40 +159,12 @@ public class WeixinServiceImpl { ...@@ -159,40 +159,12 @@ public class WeixinServiceImpl {
} }
public Map<String,String> login(String code, String encryptedData, String iv, String source) { public String login(String code) {
try{ String sessionKeyOrOpenId = getSessionKeyOrOpenId(code);
String sessionKeyOrOpenId = getSessionKeyOrOpenId(code); return sessionKeyOrOpenId;
JSONObject openInfo = JSONObject.parseObject(sessionKeyOrOpenId);
String cutomerId = openInfo.getString("openid");
// Thread.sleep(1000);
String encData = this.wxDecrypt(encryptedData, sessionKeyOrOpenId, iv);
log.info("当前用户的信息为:【{}】",encData);
Customer customer = customerMapper.selectCustomerById(cutomerId);
JSONObject encDataInf = JSONObject.parseObject(encData);
if(customer ==null){
customer = new Customer();
customer.setId(cutomerId);
customer.setHeadSculpturePath(encDataInf.getString("avatarUrl"));
customer.setUserName("小呼噜"+encDataInf.getString("phoneNumber").substring(encDataInf.getString("phoneNumber").length()-4));
customer.setPhone(encDataInf.getString("phoneNumber"));
customer.setCreateTime(new Date());
if(StringUtils.isNotEmpty(source)){
customer.setSoucre(source);
}
customerMapper.insertCustomer(customer);
}
String token = tokenService.createToken(transLoginUser(customer));
Map map = new HashMap();
map.put("token",token);
map.put("phoneNumber",encDataInf.getString("phoneNumber"));
map.put("customerName",customer.getUserName());
return map;
}catch (Exception e){
log.error("微信登录发生异常",e);
throw new ServiceException("微信登录异常,请重新登录");
}
} }
private LoginUser transLoginUser(Customer customer){ private LoginUser transLoginUser(Customer customer){
SysUser user = new SysUser(); SysUser user = new SysUser();
user.setUserName(customer.getUserName()); user.setUserName(customer.getUserName());
...@@ -206,8 +178,7 @@ public class WeixinServiceImpl { ...@@ -206,8 +178,7 @@ public class WeixinServiceImpl {
public String wxDecrypt(String encryptedData, String json, String vi) throws Exception { public String wxDecrypt(String encryptedData, String json, String vi) throws Exception {
// 开始解密 // 开始解密
//:{"session_key":"G59Evf\/Em54X6WsFsrpA1g==","openid":"o2ttv5L2yufc4-VoSPhTyUnToY60"} //:{"session_key":"G59Evf\/Em54X6WsFsrpA1g==","openid":"o2ttv5L2yufc4-VoSPhTyUnToY60"}
JSONObject jsonObject = JSON.parseObject(json); String sessionKey = json;
String sessionKey = (String) jsonObject.get("session_key");
byte[] encData = Base64.decode(encryptedData); byte[] encData = Base64.decode(encryptedData);
byte[] iv = Base64.decode(vi); byte[] iv = Base64.decode(vi);
byte[] key = Base64.decode(sessionKey); byte[] key = Base64.decode(sessionKey);
...@@ -671,4 +642,37 @@ public class WeixinServiceImpl { ...@@ -671,4 +642,37 @@ public class WeixinServiceImpl {
} }
public Map<String,String> decrypt(String encryptedData, String iv, String source, String openId, String sessionKey) {
try{
String cutomerId = openId;
String encData = this.wxDecrypt(encryptedData, sessionKey, iv);
log.info("当前用户的信息为:【{}】",encData);
Customer customer = customerMapper.selectCustomerById(cutomerId);
JSONObject encDataInf = JSONObject.parseObject(encData);
if(customer ==null){
customer = new Customer();
customer.setId(cutomerId);
customer.setHeadSculpturePath(encDataInf.getString("avatarUrl"));
customer.setUserName("小呼噜"+encDataInf.getString("phoneNumber").substring(encDataInf.getString("phoneNumber").length()-4));
customer.setPhone(encDataInf.getString("phoneNumber"));
customer.setCreateTime(new Date());
if(StringUtils.isNotEmpty(source)){
customer.setSoucre(source);
}
customerMapper.insertCustomer(customer);
}
String token = tokenService.createToken(transLoginUser(customer));
Map map = new HashMap();
map.put("token",token);
map.put("phoneNumber",encDataInf.getString("phoneNumber"));
map.put("customerName",customer.getUserName());
return map;
}catch (Exception e){
log.error("微信登录发生异常",e);
throw new ServiceException("微信登录异常,请重新登录");
}
}
} }
...@@ -123,6 +123,7 @@ public class JiGuangPushServiceImpl implements JiGuangPushService { ...@@ -123,6 +123,7 @@ public class JiGuangPushServiceImpl implements JiGuangPushService {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
data.put("orderId",order.getId()); data.put("orderId",order.getId());
data.put("orderNo",order.getOrderNo()); data.put("orderNo",order.getOrderNo());
data.put("orderNumber",order.getOrderNum());
data.put("state",order.getState()); data.put("state",order.getState());
jsonObject.put("data",data); jsonObject.put("data",data);
PushBean pushBean = new PushBean(); PushBean pushBean = new PushBean();
......
...@@ -60,7 +60,7 @@ public class SendMessageUtils { ...@@ -60,7 +60,7 @@ public class SendMessageUtils {
"\"thing2\": \"$.shop.name\"," + "\"thing2\": \"$.shop.name\"," +
"\"thing7\": \"$.shop.address\"," + "\"thing7\": \"$.shop.address\"," +
"\"time6\": \"now\"," + "\"time6\": \"now\"," +
"\"thing11\": \"您的订单已经制作完成了,现在可以去取餐啦!\"" + "\"thing11\": \"您的订单制作完成了,现在可以去取餐啦!\"" +
"}" + "}" +
"}]"; "}]";
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment