Commit b4f1f0ec by wnb0128

app支付完成订单成功同步接口添加--think.wang

1 parent b97e7478
......@@ -44,8 +44,8 @@ public class PlatformUser implements Serializable {
private Integer status;
@Column(columnDefinition = "INT(11) COMMENT 'APP 账户ID'")
private Integer appAccountId;
@Column(columnDefinition = "INT(11) COMMENT '涂鸦平台ID'")
private Integer tuYaId;
@Column(columnDefinition = "VARCHAR(50) COMMENT '涂鸦平台ID'")
private String tuYaId;
@Column(columnDefinition = "INT(11) COMMENT '创建人'")
private Integer createBy;
@Column(columnDefinition = "INT(11) COMMENT '更新人'")
......
package com.glsx.shop.service.shop;
import java.util.Date;
import java.util.List;
import com.glsx.shop.bean.entity.shop.Order;
import com.glsx.shop.bean.entity.shop.OrderItem;
import com.glsx.shop.bean.entity.shop.OrderLog;
......@@ -20,6 +18,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class OrderService extends BaseService<Order, Long, OrderRepository> {
private Logger logger = LoggerFactory.getLogger(getClass());
......@@ -65,10 +66,8 @@ public class OrderService extends BaseService<Order, Long, OrderRepository> {
public void cancel(String orderSn) {
Order order = getByOrderSn(orderSn);
order.setStatus(OrderEnum.OrderStatusEnum.CANCEL.getId());
String descript = "用户取消订单";
saveOrderLog(order, descript);
saveOrderLog(order, "用户取消订单");
updateOrder(order);
}
public Order getByOrderSn(String orderSn) {
......@@ -83,8 +82,7 @@ public class OrderService extends BaseService<Order, Long, OrderRepository> {
public Order confirmReceive(String orderSn) {
Order order = getByOrderSn(orderSn);
order.setStatus(OrderEnum.OrderStatusEnum.FINISHED.getId());
String descript = "客户确认收货";
saveOrderLog(order, descript);
saveOrderLog(order, "客户确认收货");
updateOrder(order);
return order;
}
......@@ -132,15 +130,12 @@ public class OrderService extends BaseService<Order, Long, OrderRepository> {
order.setRealPrice(order.getTotalPrice());
order.setPayType(payType);
updateOrder(order);
String descript = "用户付款成功";
saveOrderLog(order, descript);
saveOrderLog(order, "用户付款成功");
}
public void send(Order order) {
String descript = "管理员(" + JwtUtil.getUsername() + ")已发货";
updateOrder(order);
saveOrderLog(order, descript);
saveOrderLog(order, "管理员(" + JwtUtil.getUsername() + ")已发货");
}
}
......@@ -13,6 +13,7 @@ import com.glsx.shop.security.UserService;
import com.glsx.shop.service.shop.PlatformCustomerService;
import com.glsx.shop.service.shop.PlatformUserService;
import com.glsx.shop.utils.HttpUtils;
import com.glsx.shop.utils.MD5;
import com.glsx.shop.utils.StringUtil;
import com.glsx.shop.web.controller.BaseController;
import org.apache.commons.lang3.StringUtils;
......@@ -63,10 +64,12 @@ public class AppLoginController extends BaseController {
return Rets.failure(ApplicationExceptionEnum.PARAM_ERROR);
}
JwtUser jwtUser = new JwtUser(); //JWT用户信息封装
Date now =new Date();
Date now = new Date();
PlatformUser user = platformUserService.findByContactNumber(userDTO.getContactNumber());
String password = new StringBuffer(userDTO.getContactNumber())
.append(userDTO.getChannel()).toString();
String tuYaId = null;
if(user != null){
result.put("tuYaId", user.getTuYaId());
jwtUser.setId(user.getId());
jwtUser.setUserName(user.getNickname());
BeanUtils.copyProperties(userDTO, user);
......@@ -76,6 +79,14 @@ public class AppLoginController extends BaseController {
user.setUpdateTime(now);
user.setCustomerId(customer.getId().intValue());
}
//防止注册时涂鸦平台服务异常
if(user.getTuYaId() == null){
tuYaId = this.syncUser(userDTO.getContactNumber(),
userDTO.getNickname(), MD5.md5(password, userDTO.getChannel())); //同步用户到涂鸦
user.setTuYaId(tuYaId);
}else{
tuYaId = user.getTuYaId();
}
platformUserService.update(user);
}else{ //用户首次注册
PlatformUser pUser = new PlatformUser();
......@@ -85,42 +96,44 @@ public class AppLoginController extends BaseController {
pUser.setCreateBy(-1);
pUser.setStatus(1); //默认用户正常
pUser.setLastLoginTime(now);
Integer tuYaId = this.syncUser(userDTO.getContactNumber()); //同步用户到涂鸦
tuYaId = this.syncUser(userDTO.getContactNumber(),
userDTO.getNickname(), MD5.md5(password, userDTO.getChannel())); //同步用户到涂鸦
pUser.setTuYaId(tuYaId);
PlatformUser returnUser = platformUserService.insert(pUser);
jwtUser.setId(returnUser.getId());
result.put("tuYaId", tuYaId);
jwtUser.setUserName(returnUser.getNickname());
}
//JWT信息缓存
jwtUser.setPassword(userDTO.getChannel());
String token = userService.loginForToken(jwtUser);
result.put("tuYaId", tuYaId);
result.put("token", token);
return Rets.success(result);
}
private Integer syncUser(String mobile){
private String syncUser(String mobile, String nickName, String password){
JSONObject object = new JSONObject();
object.put("schema", "glsx");
object.put("country_code", "86");
object.put("username", mobile);
object.put("username_type", "1");
// object.put("nick_name", "wnb");
// object.put("password", "dsadada");
object.put("username_type", 1);
object.put("nick_name", nickName);
object.put("password", password);
try {
logger.info("请求注册涂鸦平台接口地址:{}", syncUserUrl);
logger.info("请求注册涂鸦平台接口地址:{},参数:{}", syncUserUrl,object.toJSONString());
String result = HttpUtils.postJson(syncUserUrl, object.toJSONString());
logger.info("注册涂鸦平台返回结果:{}", result);
if (StringUtils.isNotEmpty(result)) {
JSONObject json = JSON.parseObject(result);
if (json.containsKey("result")) {
JSONObject jsonObject = json.getJSONObject("result");
return jsonObject.getInteger("uid");
return jsonObject.getString("uid");
}
}
} catch (Exception e) {
logger.error("同步涂鸦平台失败:{}", e);
}
return -1;
return null;
}
/**
......
package com.glsx.shop.mobile.controller;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.glsx.shop.bean.constant.CfgKey;
import com.glsx.shop.bean.constant.factory.PageFactory;
import com.glsx.shop.bean.entity.shop.Address;
......@@ -30,11 +27,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* @author glsx
......@@ -99,8 +96,7 @@ public class OrderController extends BaseController {
public Object save(
@RequestParam("idAddress") Long idAddress,
@RequestParam(value = "message", required = false) String message,
@RequestParam(value = "idCarts") String idCarts
) {
@RequestParam(value = "idCarts") String idCarts) {
Long idUser = getIdUser();
List<SearchFilter> filters = Lists.newArrayList(
......@@ -108,7 +104,6 @@ public class OrderController extends BaseController {
SearchFilter.build("id", SearchFilter.Operator.IN, StringUtil.splitForLong(idCarts, ","))
);
List<Cart> cartList = cartService.queryAll(filters);
Order order = new Order();
order.setIdUser(idUser);
Address address = addressService.get(idAddress);
......@@ -153,16 +148,15 @@ public class OrderController extends BaseController {
@RequestMapping(value = "getExpressInfo/{orderSn}", method = RequestMethod.GET)
public Object getExpressInfo(@PathVariable(value = "orderSn") String orderSn) {
Order order = orderService.getByOrderSn(orderSn);
String apiKdniaoUserid = cfgService.getCfgValue(CfgKey.API_KDNIAO_USERID);
if (StringUtil.isEmpty(apiKdniaoUserid)) {
String apiKdUserId = cfgService.getCfgValue(CfgKey.API_KDNIAO_USERID);
if (StringUtil.isEmpty(apiKdUserId)) {
//该商城暂无配置物流查询服务
throw new ApplicationException(ApplicationExceptionEnum.SERVER_ERROR);
}
KdniaoResponse response = kdniaoService.realTimeQuery(order.getShippingSn(), order.getExpress().getCode());
Map data = Maps.newHashMap(
"order", order,
"expressInfo", response
);
KdniaoResponse response = kdniaoService.realTimeQuery(
order.getShippingSn(), order.getExpress().getCode());
Map data = Maps.newHashMap("order", order,
"expressInfo", response);
return Rets.success(data);
}
}
......@@ -11,11 +11,7 @@ import com.glsx.shop.service.shop.ShopUserService;
import com.glsx.shop.utils.StringUtil;
import com.glsx.shop.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* @author glsx
......@@ -56,6 +52,21 @@ public class PayController extends BaseController {
return msg;
}
@RequestMapping(value = "success/{orderSn}/{payId}", method = RequestMethod.POST)
public Object cancel(@PathVariable("orderSn") String orderSn,
@PathVariable("payId") String payId) {
Order order = orderService.getByOrderSn(orderSn);
if (order == null) {
return Rets.failure("订单不存在sn = " + orderSn);
}
if (order.hasPayed()) { // 检查这个订单是否已经处理过
return Rets.success("订单已经处理成功!");
}
order.setPayId(payId);
orderService.paySuccess(order, OrderEnum.PayTypeEnum.UN_SEND.getKey());
return Rets.success();
}
/**
* 查询支付结果
*
......
package com.glsx.shop.service;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
......@@ -22,6 +19,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
/**
* 微信支付
*
......@@ -59,20 +60,16 @@ public class WeixinPayService {
public String resultNotify() {
String xmlResult = null;
try {
HttpServletRequest request = HttpUtil.getRequest();
xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
} catch (IOException e) {
logger.error("解析微信支付结果通知异常", e);
return WxPayNotifyResponse.fail(e.getMessage());
}
WxPayOrderNotifyResult result = null;
try {
result = wxPayService.parseOrderNotifyResult(xmlResult);
if (!WxPayConstants.ResultCode.SUCCESS.equals(result.getResultCode())) {
logger.error(xmlResult);
throw new WxPayException("微信通知支付失败!");
......@@ -82,31 +79,24 @@ public class WeixinPayService {
throw new WxPayException("微信通知支付失败!");
}
} catch (WxPayException e) {
e.printStackTrace();
return WxPayNotifyResponse.fail(e.getMessage());
}
logger.info("处理腾讯支付平台的订单支付", Json.toJson(result));
String orderSn = result.getOutTradeNo();
String payId = result.getTransactionId();
Integer totalFee = result.getTotalFee();
Order order = orderService.getByOrderSn(orderSn);
if (order == null) {
return WxPayNotifyResponse.fail("订单不存在 sn=" + orderSn);
}
// 检查这个订单是否已经处理过
if (order.hasPayed()) {
return WxPayNotifyResponse.success("订单已经处理成功!");
}
// 检查支付订单金额
if (totalFee.intValue() != order.getTotalPrice().intValue()) {
return WxPayNotifyResponse.fail(order.getOrderSn() + " : 支付金额不符合 totalFee=" + totalFee);
}
order.setPayId(payId);
orderService.paySuccess(order, OrderEnum.PayTypeEnum.UN_SEND.getKey());
//todo 发送短信通知
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!