|
|
@@ -20,8 +20,13 @@ import com.zhongzheng.common.utils.http.HttpUtils;
|
|
|
import com.zhongzheng.common.utils.ip.IpUtils;
|
|
|
import com.zhongzheng.common.utils.polyv.PolyvUtils;
|
|
|
import com.zhongzheng.common.utils.wxpay.*;
|
|
|
+import com.zhongzheng.modules.exam.service.IExamNoteService;
|
|
|
+import com.zhongzheng.modules.order.bo.OrderGoodsAddBo;
|
|
|
+import com.zhongzheng.modules.order.bo.OrderGoodsQueryBo;
|
|
|
import com.zhongzheng.modules.order.domain.Order;
|
|
|
+import com.zhongzheng.modules.order.service.IOrderGoodsService;
|
|
|
import com.zhongzheng.modules.order.service.IOrderService;
|
|
|
+import com.zhongzheng.modules.order.vo.OrderGoodsVo;
|
|
|
import com.zhongzheng.modules.polyv.bo.PolyvVideoAddBo;
|
|
|
import com.zhongzheng.modules.polyv.bo.PolyvVideoEditBo;
|
|
|
import com.zhongzheng.modules.polyv.bo.PolyvVideoQueryBo;
|
|
|
@@ -32,6 +37,8 @@ import com.zhongzheng.modules.polyv.mapper.PolyvVideoMapper;
|
|
|
import com.zhongzheng.modules.polyv.service.IPolyvVideoService;
|
|
|
import com.zhongzheng.modules.polyv.vo.PolyvVideoQuerVo;
|
|
|
import com.zhongzheng.modules.polyv.vo.PolyvVideoVo;
|
|
|
+import com.zhongzheng.modules.user.bo.OrderPossessUserAddBo;
|
|
|
+import com.zhongzheng.modules.user.service.IOrderPossessUserService;
|
|
|
import com.zhongzheng.modules.wx.service.IWxPayService;
|
|
|
import com.zhongzheng.modules.wx.vo.WxPayVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -84,6 +91,12 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
@Autowired
|
|
|
private IOrderService iOrderService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IOrderPossessUserService iOrderPossessUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderGoodsService iOrderGoodsService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Map<String, String> payment(String out_trade_no,String openid,String body,String price) {
|
|
|
@@ -112,7 +125,7 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
result.put("package","prepay_id="+resp.get("prepay_id"));
|
|
|
result.put("signType","MD5");
|
|
|
result.put("sign", WXPayUtil.generateSignature(result, key, WXPayConstants.SignType.MD5));
|
|
|
- System.out.println(resp);
|
|
|
+ // System.out.println(resp);
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -134,19 +147,12 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
if("SUCCESS".equals(result_code)){
|
|
|
String out_trade_no = notifyMap.get("out_trade_no");
|
|
|
String transaction_id = notifyMap.get("transaction_id");
|
|
|
- Order order = iOrderService.queryByOrderSn(out_trade_no);
|
|
|
- if(order.getOrderStatus()==0){
|
|
|
- order.setOrderStatus(1);
|
|
|
- order.setPayTime(DateUtils.getNowTime());
|
|
|
- order.setTransid(transaction_id);
|
|
|
- order.setOrderGeneral(out_trade_no);
|
|
|
- if(iOrderService.updateById(order)){
|
|
|
- Map<String,String> result = new HashMap<>();
|
|
|
- result.put("return_code","<![CDATA[SUCCESS]]>");
|
|
|
- result.put("return_msg","<![CDATA[OK]]>");
|
|
|
- String resultXml = WXPayUtil.mapToXml(result);
|
|
|
- return resultXml;
|
|
|
- }
|
|
|
+ if(dealOrder(out_trade_no,transaction_id)){
|
|
|
+ Map<String,String> result = new HashMap<>();
|
|
|
+ result.put("return_code","<![CDATA[SUCCESS]]>");
|
|
|
+ result.put("return_msg","<![CDATA[OK]]>");
|
|
|
+ String resultXml = WXPayUtil.mapToXml(result);
|
|
|
+ return resultXml;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -159,64 +165,29 @@ public class WxPayServiceImpl implements IWxPayService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 不需要证书的请求
|
|
|
- * @param urlSuffix String
|
|
|
- * @param reqData 向wxpay post的请求数据
|
|
|
- * @param connectTimeoutMs 超时时间,单位是毫秒
|
|
|
- * @param readTimeoutMs 超时时间,单位是毫秒
|
|
|
- * @return API返回数据
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- public String requestWithoutCert(String urlSuffix, Map<String, String> reqData,
|
|
|
- int connectTimeoutMs, int readTimeoutMs) throws Exception {
|
|
|
- String msgUUID = reqData.get("nonce_str");
|
|
|
- String reqBody = WXPayUtil.mapToXml(reqData);
|
|
|
- String resp = this.wxPayRequest.requestWithoutCert(urlSuffix, msgUUID, reqBody, connectTimeoutMs, readTimeoutMs, autoReport);
|
|
|
- return resp;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 处理 HTTPS API返回数据,转换成Map对象。return_code为SUCCESS时,验证签名。
|
|
|
- * @param xmlStr API返回的XML格式数据
|
|
|
- * @return Map类型数据
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- public Map<String, String> processResponseXml(String xmlStr) throws Exception {
|
|
|
- String RETURN_CODE = "return_code";
|
|
|
- String return_code;
|
|
|
- Map<String, String> respData = WXPayUtil.xmlToMap(xmlStr);
|
|
|
- if (respData.containsKey(RETURN_CODE)) {
|
|
|
- return_code = respData.get(RETURN_CODE);
|
|
|
- }
|
|
|
- else {
|
|
|
- throw new Exception(String.format("No `return_code` in XML: %s", xmlStr));
|
|
|
- }
|
|
|
|
|
|
- if (return_code.equals(WXPayConstants.FAIL)) {
|
|
|
- return respData;
|
|
|
- }
|
|
|
- else if (return_code.equals(WXPayConstants.SUCCESS)) {
|
|
|
- if (this.isResponseSignatureValid(respData)) {
|
|
|
- return respData;
|
|
|
- }
|
|
|
- else {
|
|
|
- throw new Exception(String.format("Invalid sign value in XML: %s", xmlStr));
|
|
|
+ private boolean dealOrder(String out_trade_no,String transaction_id){
|
|
|
+ Order order = iOrderService.queryByOrderSn(out_trade_no);
|
|
|
+ if(order.getOrderStatus()==0){
|
|
|
+ order.setOrderStatus(1);
|
|
|
+ order.setPayTime(DateUtils.getNowTime());
|
|
|
+ order.setTransid(transaction_id);
|
|
|
+ order.setOrderGeneral(out_trade_no);
|
|
|
+ if(iOrderService.updateById(order)){
|
|
|
+ OrderGoodsQueryBo bo = new OrderGoodsQueryBo();
|
|
|
+ bo.setOrderSn(out_trade_no);
|
|
|
+ List<OrderGoodsVo> goodsList = iOrderGoodsService.queryList(bo);
|
|
|
+ for (OrderGoodsVo g : goodsList) {
|
|
|
+ //添加入我的学习
|
|
|
+ OrderPossessUserAddBo addBo = new OrderPossessUserAddBo();
|
|
|
+ addBo.setPossessId(g.getGoodsId());
|
|
|
+ addBo.setTypeId(g.getGoodsType());
|
|
|
+ addBo.setSourceId(0);//订单来源
|
|
|
+ iOrderPossessUserService.insertByAddBo(addBo);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- throw new Exception(String.format("return_code value %s is invalid in XML: %s", return_code, xmlStr));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断xml数据的sign是否有效,必须包含sign字段,否则返回false。
|
|
|
- *
|
|
|
- * @param reqData 向wxpay post的请求数据
|
|
|
- * @return 签名是否有效
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- public boolean isResponseSignatureValid(Map<String, String> reqData) throws Exception {
|
|
|
- // 返回数据的签名方式和请求中给定的签名方式是一致的
|
|
|
- return WXPayUtil.isSignatureValid(reqData, key, this.signType);
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|