Commit d06db564 by weijiguang

Merge remote-tracking branch 'origin/v2' into v2

parents 6c33c84c 28bcd52d
......@@ -68,7 +68,7 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
@Service
public class WeixinServiceImpl {
public class WeixinServiceImpl {
private static final Logger log = LoggerFactory.getLogger(WeixinServiceImpl.class);
@Autowired
......@@ -168,15 +168,15 @@ public class WeixinServiceImpl {
}
}
public String login(String code) {
public String login(String code) {
String sessionKeyOrOpenId = getSessionKeyOrOpenId(code);
return sessionKeyOrOpenId;
}
private LoginUser transLoginUser(Customer customer){
private LoginUser transLoginUser(Customer customer) {
SysUser user = new SysUser();
user.setUserName(customer.getUserName());
LoginUser loginUser = new LoginUser(user,null);
LoginUser loginUser = new LoginUser(user, null);
loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setOpenId(customer.getId());
user.setPhonenumber(customer.getPhone());
......@@ -209,9 +209,9 @@ public class WeixinServiceImpl {
order.setOut_trade_no("wuyye9w8akwbq1nc60o4affwwqnxh9dn");
//order.setSign_type("MD5");
//生成签名
String sign = Signature.getSign(order,key);
String sign = Signature.getSign(order, key);
order.setSign(sign);
String result = restTemplate.postForObject(queryUrl,order,String.class);
String result = restTemplate.postForObject(queryUrl, order, String.class);
System.out.println(result);
XStream xStream = new XStream();
xStream.alias("xml", QueryReturnInfo.class);
......@@ -230,7 +230,7 @@ public class WeixinServiceImpl {
@Autowired
private WxPayService wxPayService;
public Map<String, String> weChatPay(HttpServletRequest r,String body,String orderNo,String openId,int money) {
public Map<String, String> weChatPay(HttpServletRequest r, String body, String orderNo, String openId, int money) {
/**
* 处理内部业务,校验订单等
*/
......@@ -248,7 +248,7 @@ public class WeixinServiceImpl {
//回调的 URL 地址
.notifyUrl("http://我们的域名/api/client/pay/weChatPayNotify")
.build();
WxPayUnifiedOrderResult wxPayUnifiedOrderResult =null;
WxPayUnifiedOrderResult wxPayUnifiedOrderResult = null;
try {
wxPayUnifiedOrderResult = wxPayService.unifiedOrder(wxPayUnifiedOrderRequest);
} catch (WxPayException e) {
......@@ -258,7 +258,7 @@ public class WeixinServiceImpl {
return null;
}
public String refund(String orderNo,String refundNo,Integer totalFee,Integer refundFee) {
public String refund(String orderNo, String refundNo, Integer totalFee, Integer refundFee) {
//申请退款
WxPayRefundRequest refundInfo = WxPayRefundRequest.newBuilder()
//订单号
......@@ -291,12 +291,8 @@ public class WeixinServiceImpl {
}
public Map<String, String> pay(HttpServletRequest r,String body,String orderNo,String openId,int money) {
try{
public Map<String, String> pay(HttpServletRequest r, String body, String orderNo, String openId, int money) {
try {
HttpClientUtils client = new HttpClientUtils(url);
//组装接口参数
Map<String, String> params = new HashMap<>();
......@@ -327,22 +323,22 @@ public class WeixinServiceImpl {
Map<String, String> resultMap = WXPayUtil.xmlToMap(resultXml);
//错误处理
if("FAIL".equals(resultMap.get("return_code")) || "FAIL".equals(resultMap.get("result_code"))){
if ("FAIL".equals(resultMap.get("return_code")) || "FAIL".equals(resultMap.get("result_code"))) {
log.error("微信支付统一下单错误 ===> {} ", resultXml);
throw new RuntimeException("微信支付统一下单错误");
}
long time = System.currentTimeMillis() / 1000;
Map<String,String> signInfo =new HashMap<>();
signInfo.put("appId",appid);
signInfo.put("timeStamp",String.valueOf(time));
signInfo.put("nonceStr",WXPayUtil.generateNonceStr());
signInfo.put("repay_id","prepay_id=" + resultMap.get("prepay_id"));
signInfo.put("signType","MD5");
Map<String, String> signInfo = new HashMap<>();
signInfo.put("appId", appid);
signInfo.put("timeStamp", String.valueOf(time));
signInfo.put("nonceStr", WXPayUtil.generateNonceStr());
signInfo.put("repay_id", "prepay_id=" + resultMap.get("prepay_id"));
signInfo.put("signType", "MD5");
//生成签名
Map<String, String> payInfo = new HashMap<>();
payInfo.put("appId",appid);
payInfo.put("appId", appid);
payInfo.put("timeStamp", signInfo.get("timeStamp"));
payInfo.put("nonceStr", signInfo.get("nonceStr"));
payInfo.put("package", signInfo.get("repay_id"));
......@@ -352,21 +348,23 @@ public class WeixinServiceImpl {
// 此处可以写唤起支付前的业务逻辑
// 业务逻辑结束 回传给小程序端唤起支付
return payInfo;
}catch (Exception e){
log.error("微信支付发生异常",e);
} catch (Exception e) {
log.error("微信支付发生异常", e);
throw new ServiceException("微信支付异常");
}
}
public String wxNotify(HttpServletRequest request) throws Exception {
@Transactional
public synchronized String wxNotify(HttpServletRequest request) throws Exception {
Map<String, String> returnMap = new HashMap<>();//应答对象
//处理通知参数
String body = this.readData(request);
log.info("wx notify receive origin: \n{}", body);
//验签
if(!WXPayUtil.isSignatureValid(body, key)) {
if (!WXPayUtil.isSignatureValid(body, key)) {
log.error("通知验签失败");
//失败应答
returnMap.put("return_code", "FAIL");
......@@ -377,8 +375,9 @@ public class WeixinServiceImpl {
//解析xml数据
Map<String, String> notifyMap = WXPayUtil.xmlToMap(body);
log.info("wx notify receive decode: \n{}", JSONObject.toJSONString(notifyMap));
//判断通信和业务是否成功
if(!"SUCCESS".equals(notifyMap.get("return_code")) || !"SUCCESS".equals(notifyMap.get("result_code"))) {
if (!"SUCCESS".equals(notifyMap.get("return_code")) || !"SUCCESS".equals(notifyMap.get("result_code"))) {
log.error("失败");
//失败应答
returnMap.put("return_code", "FAIL");
......@@ -400,33 +399,33 @@ public class WeixinServiceImpl {
// }
//处理订单
if(lock.tryLock()) {
Order order = new Order();
order.setOrderNo(orderNo);
List<Order> orders = orderService.selectOrderList(order);
if (orders.isEmpty()) {
returnMap.put("return_code", "FAIL");
returnMap.put("return_msg", "没有该订单");
return WXPayUtil.mapToXml(returnMap);
}
order = orders.get(0);
try {
//处理重复的通知
//接口调用的幂等性:无论接口被调用多少次,产生的结果是一致的。
String orderStatus = order.getState();
log.info("order current status: {}", orderStatus);
if (OrderStatusConstant.Unpaid.equals(orderStatus)) {
//更新订单状态
order.setPayTime(new Date());
order.setState(OrderStatusConstant.Paid);
order.setPickCode(generatePickCode(order));
orderService.updateOrder(order);
}
} finally {
//要主动释放锁
lock.unlock();
}
// if (lock.tryLock()) {
Order order = new Order();
order.setOrderNo(orderNo);
List<Order> orders = orderService.selectOrderList(order);
if (orders.isEmpty()) {
returnMap.put("return_code", "FAIL");
returnMap.put("return_msg", "没有该订单");
return WXPayUtil.mapToXml(returnMap);
}
order = orders.get(0);
// try {
//处理重复的通知
//接口调用的幂等性:无论接口被调用多少次,产生的结果是一致的。
String orderStatus = order.getState();
log.info("order current status: {}", orderStatus);
if (OrderStatusConstant.Unpaid.equals(orderStatus)) {
//更新订单状态
order.setPayTime(new Date());
order.setState(OrderStatusConstant.Paid);
order.setPickCode(generatePickCode(order));
orderService.updateOrder(order);
}
/*} finally {
//要主动释放锁
lock.unlock();
}*/
// }
returnMap.put("return_code", "SUCCESS");
returnMap.put("return_msg", "OK");
String returnXml = WXPayUtil.mapToXml(returnMap);
......@@ -467,7 +466,7 @@ public class WeixinServiceImpl {
Order order = new Order();
order.setOrderNo(orderNo);
List<Order> orders = orderService.selectOrderList(order);
if(orders.isEmpty()){
if (orders.isEmpty()) {
return "没有该订单";
}
......@@ -483,11 +482,11 @@ public class WeixinServiceImpl {
// }
//处理订单
if(lock.tryLock()){
if (lock.tryLock()) {
try {
//处理重复的通知
//接口调用的幂等性:无论接口被调用多少次,产生的结果是一致的。
String orderStatus =order.getState();
String orderStatus = order.getState();
if (OrderStatusConstant.Unpaid.equals(orderStatus)) {
//更新订单状态
order.setPayTime(new Date());
......@@ -657,76 +656,76 @@ public class WeixinServiceImpl {
shop1.setOrderState(1);
}
String province = shop1.getProvince();
if(proString.contains(province)){
if (proString.contains(province)) {
for (JSONObject provinceObject : proviceList) {
if(province.equals(provinceObject.getString("value"))){
if (province.equals(provinceObject.getString("value"))) {
JSONArray cityChild = provinceObject.getJSONArray("children");
boolean cityboo =true;
for(int i=0;i<cityChild.size();i++){
boolean cityboo = true;
for (int i = 0; i < cityChild.size(); i++) {
JSONObject city = cityChild.getJSONObject(i);
if(shop1.getCity().equals(city.getString("value"))){
cityboo =false;
if (shop1.getCity().equals(city.getString("value"))) {
cityboo = false;
JSONArray zooeObject = city.getJSONArray("children");
boolean zoneBoo = true;
for(int j=0;j<zooeObject.size();j++){
for (int j = 0; j < zooeObject.size(); j++) {
JSONObject zooe = zooeObject.getJSONObject(j);
if(shop1.getZone().equals(zooe.getString("value"))){
if (shop1.getZone().equals(zooe.getString("value"))) {
zoneBoo = false;
JSONArray shopInfos = zooe.getJSONArray("shops");
shopInfos.add(shop1);
ArrayList<Shop> shopList = (ArrayList<Shop>) shopInfos.toJavaList(Shop.class);
List<Shop> collect = shopList.stream().sorted((a, b) -> a.getDistance().compareTo(b.getDistance())).collect(Collectors.toList());
zooe.put("shops",collect);
zooe.put("shops", collect);
}
}
if(zoneBoo){
JSONObject zone =new JSONObject();
zone.put("value",shop1.getZone());
zone.put("name",JSONPath.read(areaData,String.format(zoneString,province,shop1.getCity(),shop1.getZone())));
if (zoneBoo) {
JSONObject zone = new JSONObject();
zone.put("value", shop1.getZone());
zone.put("name", JSONPath.read(areaData, String.format(zoneString, province, shop1.getCity(), shop1.getZone())));
zooeObject.add(zone);
List<Shop> shopList = new ArrayList<>();
shopList.add(shop1);
zone.put("shops",shopList);
zone.put("shops", shopList);
}
}
}
if(cityboo){
if (cityboo) {
JSONObject city = new JSONObject();
city.put("value",shop1.getCity());
city.put("name",JSONPath.read(areaData,String.format(cityString,province,shop1.getCity())));
city.put("value", shop1.getCity());
city.put("name", JSONPath.read(areaData, String.format(cityString, province, shop1.getCity())));
cityChild.add(city);
JSONObject zone =new JSONObject();
zone.put("value",shop1.getZone());
zone.put("name",JSONPath.read(areaData,String.format(zoneString,province,shop1.getCity(),shop1.getZone())));
JSONObject zone = new JSONObject();
zone.put("value", shop1.getZone());
zone.put("name", JSONPath.read(areaData, String.format(zoneString, province, shop1.getCity(), shop1.getZone())));
List<Shop> shopList = new ArrayList<>();
shopList.add(shop1);
zone.put("shops",shopList);
zone.put("shops", shopList);
List<JSONObject> zones = new ArrayList<>();
zones.add(zone);
city.put("children",zones);
city.put("children", zones);
}
}
}
}else{
} else {
proString.add(province);
JSONObject provice = new JSONObject();
provice.put("value",province);
provice.put("value", province);
String format = String.format(provinceString, province);
provice.put("name",JSONPath.read(areaData,format));
provice.put("name", JSONPath.read(areaData, format));
proviceList.add(provice);
JSONObject city = new JSONObject();
city.put("value",shop1.getCity());
city.put("name",JSONPath.read(areaData,String.format(cityString,province,shop1.getCity())));
List<JSONObject> citys =new ArrayList<>();
city.put("value", shop1.getCity());
city.put("name", JSONPath.read(areaData, String.format(cityString, province, shop1.getCity())));
List<JSONObject> citys = new ArrayList<>();
citys.add(city);
provice.put("children",citys);
JSONObject zone =new JSONObject();
zone.put("value",shop1.getZone());
zone.put("name",JSONPath.read(areaData,String.format(zoneString,province,shop1.getCity(),shop1.getZone())));
provice.put("children", citys);
JSONObject zone = new JSONObject();
zone.put("value", shop1.getZone());
zone.put("name", JSONPath.read(areaData, String.format(zoneString, province, shop1.getCity(), shop1.getZone())));
List<Shop> shopList = new ArrayList<>();
shopList.add(shop1);
zone.put("shops", shopList);
......
......@@ -92,8 +92,10 @@ public class OrderServiceImpl implements IOrderService {
public Order selectOrderById(Long id) {
Order order = orderMapper.selectOrderById(id);
order.setShop(shopMapper.selectShopById(order.getShopId()));
String pickCode = stringRedisTemplate.opsForValue().get(order.getPickCode());
order.setPickCode(pickCode);
if (!StringUtils.isEmpty(order.getPickCode())) {
String pickCode = stringRedisTemplate.opsForValue().get(order.getPickCode());
order.setPickCode(pickCode);
}
OrderSnapshot orderSnapshot = orderSnapshotService.selectOrderSnapshotByOrderId(order.getId());
String snapshot = orderSnapshot.getSnapshot();
List<OrderDetail> orderDetails = JSONObject.parseArray(snapshot, OrderDetail.class);
......@@ -615,8 +617,10 @@ public class OrderServiceImpl implements IOrderService {
String waitTime = getWaitTimeByOrderId(order.getId());
Map<String, String> map = new HashMap<>();
map.put("waitTime", waitTime);
String pickCode = stringRedisTemplate.opsForValue().get(order.getPickCode());
map.put("pickCode", pickCode);
if (StringUtils.isNotEmpty(order.getPickCode())) {
String pickCode = stringRedisTemplate.opsForValue().get(order.getPickCode());
map.put("pickCode", pickCode);
}
map.put("orderNum", order.getOrderNum());
map.put("state", order.getState());
return map;
......
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