diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighGoldRecController.java b/hai-bweb/src/main/java/com/bweb/controller/HighGoldRecController.java index c0ae1f0d..7964a4d3 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighGoldRecController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighGoldRecController.java @@ -46,11 +46,13 @@ public class HighGoldRecController { @ResponseBody @ApiOperation(value = "获取金币情况") public ResponseData getGoldRecList(@RequestParam(name = "goldType", required = false) Integer goldType, + @RequestParam(name = "resType", required = false) Integer resType, @RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageSize", required = true) Integer pageSize) { try { Map map = new HashMap<>(); map.put("goldType", goldType); + map.put("resType", resType); PageHelper.startPage(pageNum,pageSize); return ResponseMsgUtil.success(new PageInfo<>(highGoldRecService.getGoldRec(map))); diff --git a/hai-bweb/src/main/java/com/bweb/controller/SecUserController.java b/hai-bweb/src/main/java/com/bweb/controller/SecUserController.java index 1d551ce9..fdff6fe2 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/SecUserController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/SecUserController.java @@ -72,7 +72,7 @@ public class SecUserController { //查询用户 SecUser secUser = secUserService.findById(userId); if(secUser == null){ - log.error("BaseMemberController --> sendUserPass() error!","未找到用户"); + log.error("BaseMemberController --> sendUserPass() error!",""); throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, ""); } if(!secUser.getPassword().equals(MD5Util.encode(oldPassword.getBytes()))) { diff --git a/hai-bweb/src/main/java/com/bweb/controller/TelApiController.java b/hai-bweb/src/main/java/com/bweb/controller/TelApiController.java index 7172b4c8..86f1c12a 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/TelApiController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/TelApiController.java @@ -1,6 +1,5 @@ package com.bweb.controller; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; @@ -8,13 +7,13 @@ import com.hai.common.exception.SysCode; import com.hai.common.pay.util.IOUtil; import com.hai.common.pay.util.XmlUtil; import com.hai.common.utils.*; -import com.hai.config.CommonSysConst; -import com.hai.config.QianZhuConfig; import com.hai.config.TelConfig; -import com.hai.entity.HighDiscount; -import com.hai.entity.HighTelOrder; -import com.hai.entity.HighUser; +import com.hai.entity.*; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; import com.hai.model.ResponseData; +import com.hai.service.HighOrderService; +import com.hai.service.HighUserService; import com.hai.service.TelApiService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -26,9 +25,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.BufferedOutputStream; import java.math.BigDecimal; -import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -44,6 +41,12 @@ public class TelApiController { @Resource private TelApiService telApiService; + @Resource + private HighOrderService highOrderService; + + @Resource + private HighUserService highUserService; + /** * 中国电信号码格式验证 手机段: 133,153,180,181,189,177,1700,173,199 **/ @@ -182,4 +185,17 @@ public class TelApiController { } } + @RequestMapping(value = "/getTest", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "测试接口") + public ResponseData getTest() { + try { + + + return ResponseMsgUtil.success("1"); + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java index 9f9be337..d17de229 100644 --- a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -119,6 +119,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/order/qzOrderToPay") .excludePathPatterns("/czOrder/orderRefundNotify") .excludePathPatterns("/tPig/*") + .excludePathPatterns("/telApi/*") ; } diff --git a/hai-cweb/src/main/java/com/cweb/config/WxMsgConfig.java b/hai-cweb/src/main/java/com/cweb/config/WxMsgConfig.java new file mode 100644 index 00000000..dcecc399 --- /dev/null +++ b/hai-cweb/src/main/java/com/cweb/config/WxMsgConfig.java @@ -0,0 +1,55 @@ +package com.cweb.config; + +import cn.binarywang.wx.miniapp.api.WxMaMsgService; +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; +import com.hai.common.utils.DateUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + +public class WxMsgConfig { + + private static Logger log = LoggerFactory.getLogger(WxMsgConfig.class); + + public static void pushOneUser(String orderName , String price , String orderNo , Date payTime , String remark , Long orderId , String openId) { + + try { + List list = new ArrayList<>(); + + Map m = new HashMap<>(); + + m.put("thing1", orderName); + m.put("amount2", price + "元"); + m.put("character_string3", orderNo); + m.put("time4", DateUtil.date2String(payTime , "yyyy年MM月dd日 HH:mm:ss")); + m.put("thing6", remark); + + for (String key: m.keySet()) { + WxMaSubscribeMessage.Data msgElement = new WxMaSubscribeMessage.Data(); + msgElement.setName(key); + msgElement.setValue(m.get(key)); + list.add(msgElement); + } + + WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage(); + subscribeMessage.setToUser(openId); // 小程序openId + subscribeMessage.setTemplateId("oUvaCPeeOg4wH6HTvCcSabU6FnzXUXOBXsqBYAPOV-U"); + subscribeMessage.setData(list); + subscribeMessage.setPage("pages/user/order_details/order_details?id=" + orderId); + subscribeMessage.setMiniprogramState("developer"); + + final WxMaService wxService = WxMaConfiguration.getMaService(); + WxMaMsgService maMsgService = wxService.getMsgService(); + maMsgService.sendSubscribeMsg(subscribeMessage); + } catch (Exception e) { + log.error(String.valueOf(e)); + } + + } + + + + +} diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java index a9807b4f..e659e90c 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java @@ -6,6 +6,7 @@ import com.cweb.config.SysConst; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.*; import com.hai.config.*; @@ -13,10 +14,20 @@ import com.hai.entity.*; import com.hai.model.HighMerchantModel; import com.hai.model.HighMerchantStoreModel; import com.hai.model.ResponseData; +import com.hai.model.ResultProfitSharing; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; +import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; @@ -24,6 +35,10 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.net.ssl.SSLContext; +import java.io.FileInputStream; +import java.math.BigDecimal; +import java.security.KeyStore; import java.util.*; /** @@ -47,6 +62,11 @@ public class HighTestController { @Resource private HighGasOilPriceService highGasOilPriceService; + @Resource + private HighOrderService highOrderService; + + @Resource + private HighProfitSharingRecordService highProfitSharingRecordService; @RequestMapping(value = "/initTYMerchantStore", method = RequestMethod.GET) @ResponseBody @@ -218,26 +238,123 @@ public class HighTestController { } } - @RequestMapping(value = "/test3", method = RequestMethod.GET) + @RequestMapping(value = "/splitSccount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "测试") - public ResponseData test3() { + public ResponseData splitSccount() { try { - // return ResponseMsgUtil.success(HuiLianTongUnionCardConfig.resolveResponse("T3xbPEKEXV9+CbBw8D1B+N2jk8xwa55s0Bde48c49YDMmj1rv5nOrkawWt8fskSihNw0wugKUT1x\\nWjHhIN8af7NylRVfhJvbeja2Zjjxnwk3FEKgyvIvJnk3QgiY4aghqQcGKxDOlAxT/kjrkDd2ESu1\\nIWkpi+0HGnG3rKSL6+a1Nu7aW+rPHwXUOmHSgWFZFb9HhlfKI/jml3GhMZBWsZFirayyMMi8UKrd\\nYN7ANPEB/6uV9iVtpLF5Kz8M2+GpI0EqRhPFAH2u3Q/RSgW8ei2ZbOY9NnbkdwuOjU93wgJxdY1Y\\n93hvLYNe1i9QkSM1")); - // 获取token - JSONObject tokenObject = HuiLianTongConfig.getToken(); - if (!tokenObject.getString("result").equals("success")) { - log.error("HighCouponController -> insertCoupon() error!","获取token失败"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取token失败"); - } - // 推送给高速 - JSONObject returnParam = HuiLianTongConfig.couJointDist(tokenObject.getString("data"), "20JY000251", 4, "15932678659", "HF"+new Date().getTime()); + //List list = highOrderService.getErrorOrder(); + /* HighOrder order = highOrderService.getOrderByOrderNo("20210827003355621063330"); + BigDecimal rake = new BigDecimal("0.01"); - return ResponseMsgUtil.success(returnParam); + // 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 + BigDecimal wxHandlingFee = order.getPayRealPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); + BigDecimal price = order.getPayRealPrice().subtract(wxHandlingFee); + + // 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 + BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); + this.wxProfitsharing(order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount);*/ + return ResponseMsgUtil.success("分账成功"); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); } } + + public void wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { + try { + Map param = new LinkedHashMap<>(); + param.put("appid", "wx637bd6f7314daa46"); + param.put("mch_id", "1289663601"); + param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 + param.put("transaction_id" , transaction_id); + param.put("out_order_no" , out_order_no); + param.put("nonce_str" , WxUtils.makeNonStr()); + + // 分账金额 + BigDecimal porofitSharingAmount = amount; + + List> receiversList = new ArrayList<>(); + Map receiversMap = new LinkedHashMap<>(); + receiversMap.put("type", "MERCHANT_ID"); + receiversMap.put("account", "1603942866"); + receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); + receiversMap.put("description", "分给商户【惠昕石化】"); + receiversList.add(receiversMap); + param.put("receivers" , JSONObject.toJSONString(receiversList)); + String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); + param.put("sign" , signStr); + String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param)); + + // 请求分账返回的结果 + ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); + + if (!resultProfitSharing.getResult_code().equals("FAIL")) { + HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord(); + sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no()); + sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id()); + sharingRecord.setOrderId(resultProfitSharing.getOrder_id()); + sharingRecord.setStatus(resultProfitSharing.getResult_code()); + sharingRecord.setPrice(amount); + sharingRecord.setCreateTime(new Date()); + sharingRecord.setContent(resultXmL); + highProfitSharingRecordService.insert(sharingRecord); + } + + } catch (Exception e) { + log.error("CmsContentController --> getCorporateAdvertising() error!", e); + } + } + + + public CloseableHttpClient readCertificate(String mchId) throws Exception{ + /** + * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 + */ + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 + FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12"); + // FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12"); + try { + keyStore.load(instream, "1289663601".toCharArray());//这里写密码..默认是你的MCHID + } finally { + instream.close(); + } + SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "1289663601".toCharArray()).build();//这里也是写密码的 + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.getDefaultHostnameVerifier()); + // Allow TLSv1 protocol only + return HttpClients.custom().setSSLSocketFactory(sslsf).build(); + } + + public String doRefundRequest(String mchId, String url, String data) throws Exception { + + //小程序退款需要调用双向证书的认证 + CloseableHttpClient httpClient = readCertificate(mchId); + try { + HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息 + httpost.addHeader("Connection", "keep-alive"); + httpost.addHeader("Accept", "*/*"); + httpost.addHeader("Content-Type", "text/xml"); + httpost.addHeader("Host", "api.mch.weixin.qq.com"); + httpost.addHeader("X-Requested-With", "XMLHttpRequest"); + httpost.addHeader("Cache-Control", "max-age=0"); + httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); + httpost.setEntity(new StringEntity(data, "UTF-8")); + CloseableHttpResponse response = httpClient.execute(httpost); + try { + HttpEntity entity = response.getEntity(); + String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); + EntityUtils.consume(entity); + return jsonStr; + } finally { + response.close(); + } + } catch (Exception e){ + throw new RuntimeException(e); + } finally { + httpClient.close(); + } + } + } diff --git a/hai-cweb/src/main/java/com/cweb/controller/TelApiController.java b/hai-cweb/src/main/java/com/cweb/controller/TelApiController.java new file mode 100644 index 00000000..cfebe4a2 --- /dev/null +++ b/hai-cweb/src/main/java/com/cweb/controller/TelApiController.java @@ -0,0 +1,216 @@ +package com.cweb.controller; + +import com.alibaba.fastjson.JSONObject; +import com.cweb.config.WxMsgConfig; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.pay.util.IOUtil; +import com.hai.common.pay.util.XmlUtil; +import com.hai.common.utils.*; +import com.hai.config.TelConfig; +import com.hai.entity.HighChildOrder; +import com.hai.entity.HighOrder; +import com.hai.entity.HighTelOrder; +import com.hai.entity.HighUser; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; +import com.hai.model.ResponseData; +import com.hai.service.HighOrderService; +import com.hai.service.HighUserService; +import com.hai.service.TelApiService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.SortedMap; +import java.util.regex.Pattern; + +@RestController +@RequestMapping(value = "/telApi") +@Api(value = "电话费充值数据接口") +public class TelApiController { + private static Logger log = LoggerFactory.getLogger(TelApiController.class); + + @Resource + private TelApiService telApiService; + + @Resource + private HighOrderService highOrderService; + + @Resource + private HighUserService highUserService; + + /** + * 中国电信号码格式验证 手机段: 133,153,180,181,189,177,1700,173,199 + **/ + private static final String CHINA_TELECOM_PATTERN = "(^1(33|53|77|73|99|8[019])\\d{8}$)|(^1700\\d{7}$)"; + + /** + * 中国联通号码格式验证 手机段:130,131,132,155,156,185,186,145,176,1709 + **/ + private static final String CHINA_UNICOM_PATTERN = "(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\\d{8}$)|(^1709\\d{7}$)"; + + /** + * 中国移动号码格式验证 + * 手机段:134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705 + **/ + private static final String CHINA_MOBILE_PATTERN = "(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\\d{8}$)|(^1705\\d{7}$)"; + + + @RequestMapping(value = "/telPay", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "充值话费") + public ResponseData certification(@RequestBody HighTelOrder highTelOrder) { + try { + + if (StringUtils.isBlank(highTelOrder.getTel()) || + highTelOrder.getPrice() == null + ) { + log.error("telApi -> telPay() error!", "参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + int random = (int) (1 + Math.random() * (999999 - 100000 + 1)); + + Map map = new HashMap<>(); + + String mchid = "HFb44f8_10004"; + String tel = highTelOrder.getTel(); + String orderid = "HF" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5); + BigDecimal price = BigDecimal.valueOf(highTelOrder.getPrice()); + String teltype = isChinaMobilePhoneNum(highTelOrder.getTel()).toString(); + int timeout = 300; + String notify = "notify"; + String time = String.valueOf(new Date().getTime()); + String APIKEY = "483e5a68fe9bda2f7ab3f2665a0006cd"; + String sign = mchid + tel + price + orderid + teltype + notify + time + random + APIKEY; + + String param = "mchid=" + mchid + + "&tel=" + tel + + "&orderid=" + orderid + + "&price=" + price + + "&teltype=" + teltype + + "¬ify=" + notify + + "&time=" + time + + "&rand=" + random + + "&sign=" + MD5Util.encode(sign.getBytes()); + map.put("from", param); + + JSONObject object = HttpsUtils.doSmsPost("http://45.130.154.125:9998/api/telpay", map, new HashMap<>()); + return ResponseMsgUtil.success(object); + } catch (Exception e) { + log.error("HighMerchantController -> insertMerchant() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/notify", method = RequestMethod.POST) + @ApiOperation(value = "话费充值 -> 异步回调") + public void wechatNotify(HttpServletRequest request, HttpServletResponse response) { + try { + + log.info("话费充值 -> 异步通知:处理开始"); + + String notifyXml = null; // 话费充值系统发送的数据(格式) + notifyXml = IOUtil.inputStreamToString(request.getInputStream(), "UTF-8"); + + log.info("话费充值系统发送的数据:" + notifyXml); + SortedMap map = XmlUtil.parseXmlToTreeMap(notifyXml, "UTF-8"); + +// resXml = notifyService.wechatNotify(map); +// +// +// BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); +// out.write(resXml.getBytes()); +// out.flush(); +// out.close(); + log.info("话费充值 -> 异步通知:处理完成"); + } catch (Exception e) { + log.error("WechatPayController --> wechatNotify() error!", e); + } + } + + /** + * 查询电话属于哪个运营商 + * + * @param tel 手机号码 + * @return 0:不属于任何一个运营商,0:移动,1:联通,2:电信 99: 什么都不是 + */ + public Integer isChinaMobilePhoneNum(String tel) { + boolean b1 = tel != null && !tel.trim().equals("") && match(CHINA_MOBILE_PATTERN, tel); + if (b1) { + return 0; + } + b1 = tel != null && !tel.trim().equals("") && match(CHINA_UNICOM_PATTERN, tel); + if (b1) { + return 1; + } + b1 = tel != null && !tel.trim().equals("") && match(CHINA_TELECOM_PATTERN, tel); + if (b1) { + return 2; + } + return 99; + } + + /** + * 匹配函数 + * + * @param regex + * @param tel + * @return + */ + private static boolean match(String regex, String tel) { + return Pattern.matches(regex, tel); + } + + + @RequestMapping(value = "/getMemberGoods", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取渠道商获取关联商品") + public ResponseData getMemberGoods() { + try { + + JSONObject data = TelConfig.getMemberGoods(); + + return ResponseMsgUtil.success(data); + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getTest", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "测试接口") + public ResponseData getTest() { + try { + + HighOrder order = highOrderService.getOrderById(699L); + + HighUser highUser = highUserService.findByUserId(order.getMemId()); + HighChildOrder presentation = highOrderService.getChildOrderByPresentation(order.getId()); + WxMsgConfig.pushOneUser( + presentation.getGoodsName() + "(" + GoodsType.getNameByType(presentation.getGoodsType()) + ")", + String.valueOf(order.getPayPrice()), + order.getOrderNo(), + order.getPayTime(), + PayType.getNameByType(order.getPayType()), order.getId(), + highUser.getOpenId()); + + return ResponseMsgUtil.success("1"); + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java index 0c0d85e8..58429e56 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cweb.config.SysConst; +import com.cweb.config.WxMsgConfig; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; @@ -21,6 +22,8 @@ import com.hai.common.utils.ResponseMsgUtil; import com.hai.config.QianZhuConfig; import com.hai.config.TuanYouConfig; import com.hai.entity.*; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; import com.hai.model.HighCouponModel; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; @@ -96,6 +99,9 @@ public class OrderController { @Resource private HighUserCardService highUserCardService; + @Resource + private HighUserService highUserService; + /** * * @Title: orderToPay @@ -267,6 +273,22 @@ public class OrderController { highOrderService.goldPayOrder(order.getMemId(), order.getId()); + new Thread(() -> { + // 查询订单信息 + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); + } + HighUser highUser = highUserService.findByUserId(order.getMemId()); + HighChildOrder presentation = highOrderService.getChildOrderByPresentation(order.getId()); + WxMsgConfig.pushOneUser( + presentation.getGoodsName() + "(" + GoodsType.getNameByType(presentation.getGoodsType()) + ")", + String.valueOf(order.getPayPrice()), + order.getOrderNo(), + order.getPayTime(), + PayType.getNameByType(order.getPayType()), order.getId(), + highUser.getOpenId()); + }).start(); + return ResponseMsgUtil.success("支付成功"); } catch (Exception e) { log.error("orderToPay error!", e); @@ -344,6 +366,22 @@ public class OrderController { highOrderService.hltUnionCardPay(userCard.getId(), order.getId()); + new Thread(() -> { + // 查询订单信息 + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); + } + HighUser highUser = highUserService.findByUserId(order.getMemId()); + HighChildOrder presentation = highOrderService.getChildOrderByPresentation(order.getId()); + WxMsgConfig.pushOneUser( + presentation.getGoodsName() + "(" + GoodsType.getNameByType(presentation.getGoodsType()) + ")", + String.valueOf(order.getPayPrice()), + order.getOrderNo(), + order.getPayTime(), + PayType.getNameByType(order.getPayType()), order.getId(), + highUser.getOpenId()); + }).start(); + return ResponseMsgUtil.success("支付成功"); } catch (Exception e) { log.error("orderToPay error!", e); diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java index 156858b1..890e38b1 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java @@ -2,6 +2,10 @@ package com.cweb.controller.pay; import com.alibaba.fastjson.JSONObject; import com.cweb.config.SysConst; +import com.cweb.config.WxMsgConfig; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; import com.hai.common.pay.WechatPayUtil; import com.hai.common.pay.entity.WechatCallBackInfo; import com.hai.common.pay.util.IOUtil; @@ -10,13 +14,15 @@ import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; -import com.hai.entity.BsCompany; -import com.hai.entity.HighProfitSharingRecord; -import com.hai.entity.SecRegion; +import com.hai.entity.*; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; import com.hai.model.ResponseData; import com.hai.model.WxSharingOrderRequestModel; import com.hai.model.WxSharingReceiversVO; +import com.hai.service.HighOrderService; import com.hai.service.HighProfitSharingRecordService; +import com.hai.service.HighUserService; import com.hai.service.TelApiService; import com.hai.service.pay.NotifyService; import com.hai.service.pay.PayRecordService; @@ -69,6 +75,12 @@ public class WechatPayController { @Resource private WechatPayUtil wechatPayUtil; + @Resource + private HighOrderService highOrderService; + + @Resource + private HighUserService highUserService; + @Resource private TelApiService telApiService; @Resource @@ -102,6 +114,24 @@ public class WechatPayController { + "" + " "; }*/ + + new Thread(() -> { + // 查询订单信息 + HighOrder order = highOrderService.getOrderByOrderNo(map.get("out_trade_no")); + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); + } + HighUser highUser = highUserService.findByUserId(order.getMemId()); + HighChildOrder presentation = highOrderService.getChildOrderByPresentation(order.getId()); + WxMsgConfig.pushOneUser( + presentation.getGoodsName() + "(" + GoodsType.getNameByType(presentation.getGoodsType()) + ")", + String.valueOf(order.getPayPrice()), + order.getOrderNo(), + order.getPayTime(), + PayType.getNameByType(order.getPayType()), order.getId(), + highUser.getOpenId()); + }).start(); + BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); out.write(resXml.getBytes()); out.flush(); diff --git a/hai-service/src/main/java/com/hai/config/CommonSysConfig.java b/hai-service/src/main/java/com/hai/config/CommonSysConfig.java index 6cd33b97..51d1e0a2 100644 --- a/hai-service/src/main/java/com/hai/config/CommonSysConfig.java +++ b/hai-service/src/main/java/com/hai/config/CommonSysConfig.java @@ -230,4 +230,5 @@ public class CommonSysConfig { public void setTelUrl(String telUrl) { this.telUrl = telUrl; } + } diff --git a/hai-service/src/main/java/com/hai/config/TelConfig.java b/hai-service/src/main/java/com/hai/config/TelConfig.java index 85c7a6aa..1ccb332d 100644 --- a/hai-service/src/main/java/com/hai/config/TelConfig.java +++ b/hai-service/src/main/java/com/hai/config/TelConfig.java @@ -23,13 +23,6 @@ import java.util.Map; **/ public class TelConfig { - - @Resource - private OutRechargeOrderService outRechargeOrderService; - - @Resource - private OutRechargePriceService outRechargePriceService; - public static JSONObject getMemberGoods() throws Exception { Map map = new HashMap<>(); diff --git a/hai-service/src/main/java/com/hai/enum_type/GoodsType.java b/hai-service/src/main/java/com/hai/enum_type/GoodsType.java new file mode 100644 index 00000000..4f246b7d --- /dev/null +++ b/hai-service/src/main/java/com/hai/enum_type/GoodsType.java @@ -0,0 +1,46 @@ +package com.hai.enum_type; + +import java.util.Objects; + +public enum GoodsType { + + goodsType1(1 , "卡卷"), + goodsType2(2 , "金币充值"), + goodsType3(3 , "团油"), + goodsType4(4 , "KFC"), + goodsType5(5 , "电影票"), + goodsType6(6 , "话费充值") + ; + + private Integer type; + private String name; + + + GoodsType(int type , String name) { + this.type = type; + this.name = name; + } + + public static String getNameByType(Integer type) { + for (GoodsType ele : values()) { + if(Objects.equals(type,ele.getType())) return ele.getName(); + } + return null; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/hai-service/src/main/java/com/hai/enum_type/PayType.java b/hai-service/src/main/java/com/hai/enum_type/PayType.java new file mode 100644 index 00000000..fffb3af9 --- /dev/null +++ b/hai-service/src/main/java/com/hai/enum_type/PayType.java @@ -0,0 +1,44 @@ +package com.hai.enum_type; + +import java.util.Objects; + +public enum PayType { + + payType1(1 , "支付宝"), + payType2(2 , "微信"), + payType3(3 , "金币"), + payType4(4 , "汇联通工会卡") + ; + + private Integer type; + private String name; + + + PayType(int type , String name) { + this.type = type; + this.name = name; + } + + public static String getNameByType(Integer type) { + for (PayType ele : values()) { + if(Objects.equals(type,ele.getType())) return ele.getName(); + } + return null; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/hai-service/src/main/java/com/hai/service/HighOrderService.java b/hai-service/src/main/java/com/hai/service/HighOrderService.java index 4c59b4ba..109e7f6c 100644 --- a/hai-service/src/main/java/com/hai/service/HighOrderService.java +++ b/hai-service/src/main/java/com/hai/service/HighOrderService.java @@ -84,6 +84,16 @@ public interface HighOrderService { */ List getChildOrderByOrder(Long orderId); + /** + * @Author Sum1Dream + * @name getChildOrderByPresentation.java + * @Description // 根据是否赠品查询子订单 + * @Date 16:20 2021/9/7 + * @Param [orderId, isGiveAway] + * @return com.hai.entity.HighChildOrder + **/ + HighChildOrder getChildOrderByPresentation(Long orderId); + /** * @Author 胡锐 * @Description 查询子商品列表 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighGoldRecServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighGoldRecServiceImpl.java index 418c1fcd..bfe843a6 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighGoldRecServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighGoldRecServiceImpl.java @@ -44,6 +44,10 @@ public class HighGoldRecServiceImpl implements HighGoldRecService { criteria.andGoldTypeEqualTo(MapUtils.getLong(map, "goldType")); } + if (MapUtils.getLong(map, "resType") != null) { + criteria.andResTypeEqualTo(MapUtils.getInteger(map, "resType")); + } + example.setOrderByClause("create_time desc"); List list = highGoldRecMapper.selectByExample(example); for (HighGoldRec highGoldRec : list) { diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index a17a2daa..ed338459 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -8,12 +8,11 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.utils.DateUtil; import com.hai.common.utils.IDGenerator; -import com.hai.config.CommonSysConst; -import com.hai.config.HuiLianTongConfig; -import com.hai.config.HuiLianTongUnionCardConfig; -import com.hai.config.TuanYouConfig; +import com.hai.config.*; import com.hai.dao.*; import com.hai.entity.*; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; import com.hai.model.*; import com.hai.service.*; import org.apache.commons.collections4.MapUtils; @@ -82,6 +81,9 @@ public class HighOrderServiceImpl implements HighOrderService { @Resource private HighMerchantStoreService highMerchantStoreService; + @Resource + private HighOrderService highOrderService; + @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void insertOrder(HighOrder highOrder) throws Exception { @@ -321,7 +323,7 @@ public class HighOrderServiceImpl implements HighOrderService { } JSONObject consumptionResult = HuiLianTongUnionCardConfig.resolveResponse(consumption.getString("data")); if (consumptionResult.getBoolean("success") != true) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "交易失败,请使用其他支付方式"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "交易失败!"+consumptionResult.getString("message")); } // 查询用户 @@ -337,7 +339,6 @@ public class HighOrderServiceImpl implements HighOrderService { order.setPayType(4); // 支付方式: 1:支付宝 2:微信 3:金币 4:汇联通支工会卡 order.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 - for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { // 商品类型 商品类型 1:卡卷 2:金币充值 if (highChildOrder.getGoodsType() == 1) { @@ -472,8 +473,9 @@ public class HighOrderServiceImpl implements HighOrderService { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } } - updateOrder(order); } + + updateOrder(order); } @Override @@ -877,4 +879,11 @@ public class HighOrderServiceImpl implements HighOrderService { public List> getFinishGasOrder() { return highOrderMapper.selectFinishGasOrder(); } + + @Override + public HighChildOrder getChildOrderByPresentation(Long orderId) { + HighChildOrderExample example = new HighChildOrderExample(); + example.createCriteria().andOrderIdEqualTo(orderId).andGiveawayTypeEqualTo(false); + return highChildOrderMapper.selectByExample(example).get(0); + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java index 34301c88..b0aa79f6 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java @@ -136,7 +136,7 @@ public class HighUserServiceImpl implements HighUserService { HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); HighUser highUser = findByUserId(userInfoModel.getHighUser().getId()); if (highUser == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "未找到用户"); } if (StringUtils.isNotBlank(highUser.getPhone())) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已绑定手机号,请勿重复绑定"); diff --git a/hai-service/src/main/java/com/hai/service/pay/NotifyService.java b/hai-service/src/main/java/com/hai/service/pay/NotifyService.java index 7c567461..21fb5018 100644 --- a/hai-service/src/main/java/com/hai/service/pay/NotifyService.java +++ b/hai-service/src/main/java/com/hai/service/pay/NotifyService.java @@ -27,4 +27,5 @@ public interface NotifyService { * @param paramsMap 异步回调返回的参数 */ String wechatNotify(Map paramsMap) throws Exception; + } diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/CinemaOrderService.java b/hai-service/src/main/java/com/hai/service/pay/impl/CinemaOrderService.java index 0bfc6699..82e68ae5 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/CinemaOrderService.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/CinemaOrderService.java @@ -6,7 +6,11 @@ import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.HighChildOrder; import com.hai.entity.HighGasOrderPush; import com.hai.entity.HighOrder; +import com.hai.entity.HighUser; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; import com.hai.service.HighOrderService; +import com.hai.service.HighUserService; import com.hai.service.pay.PayService; import org.springframework.stereotype.Service; @@ -24,6 +28,9 @@ public class CinemaOrderService implements PayService { @Resource private HighGasOrderPushMapper highGasOrderPushMapper; + @Resource + private HighUserService highUserService; + @Override public void paySuccess(Map map, String payType) throws Exception { if (payType.equals("Alipay")) { @@ -42,6 +49,7 @@ public class CinemaOrderService implements PayService { for (HighChildOrder childOrder : order.getHighChildOrderList()) { childOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 } + highOrderService.updateOrder(order); // 支付给千猪 JSONObject object = QianZhuConfig.payMovieOrder(order.getOrderNo()); diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java index ff633c51..771a8728 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java @@ -15,9 +15,12 @@ import com.hai.dao.HighCouponCodeOtherMapper; import com.hai.dao.HighGasOrderPushMapper; import com.hai.dao.HighUserCouponMapper; import com.hai.entity.*; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; import com.hai.model.HighMerchantStoreModel; import com.hai.model.ResultProfitSharing; import com.hai.service.*; +import com.hai.service.pay.NotifyService; import com.hai.service.pay.PayService; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; @@ -78,6 +81,9 @@ public class GoodsOrderServiceImpl implements PayService { @Resource private HighCouponCodeOtherMapper highCouponCodeOtherMapper; + @Resource + private NotifyService notifyService; + @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void paySuccess(Map map, String payType) throws Exception { diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/KfcOrderService.java b/hai-service/src/main/java/com/hai/service/pay/impl/KfcOrderService.java index 0e4eff56..c01e0ed2 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/KfcOrderService.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/KfcOrderService.java @@ -7,7 +7,11 @@ import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.HighChildOrder; import com.hai.entity.HighGasOrderPush; import com.hai.entity.HighOrder; +import com.hai.entity.HighUser; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; import com.hai.service.HighOrderService; +import com.hai.service.HighUserService; import com.hai.service.pay.PayService; import org.springframework.stereotype.Service; @@ -25,6 +29,9 @@ public class KfcOrderService implements PayService { @Resource private HighGasOrderPushMapper highGasOrderPushMapper; + @Resource + private HighUserService highUserService; + @Override public void paySuccess(Map map, String payType) throws Exception { if (payType.equals("Alipay")) { @@ -44,6 +51,7 @@ public class KfcOrderService implements PayService { childOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 } highOrderService.updateOrder(order); + // 支付给千猪 JSONObject object = QianZhuConfig.payKfcOrder(order.getOrderNo()); diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/MobileOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/MobileOrderServiceImpl.java index 57dd9c96..bfcc4a3a 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/MobileOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/MobileOrderServiceImpl.java @@ -6,7 +6,11 @@ import com.hai.dao.HighGasOrderPushMapper; import com.hai.entity.HighChildOrder; import com.hai.entity.HighGasOrderPush; import com.hai.entity.HighOrder; +import com.hai.entity.HighUser; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; import com.hai.service.HighOrderService; +import com.hai.service.HighUserService; import com.hai.service.pay.PayService; import org.springframework.stereotype.Service; @@ -31,6 +35,9 @@ public class MobileOrderServiceImpl implements PayService { @Resource private HighGasOrderPushMapper highGasOrderPushMapper; + @Resource + private HighUserService highUserService; + @Override public void paySuccess(Map map, String payType) throws Exception { if (payType.equals("Alipay")) { diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/NotifyServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/NotifyServiceImpl.java index d8cd592b..fdb29d39 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/NotifyServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/NotifyServiceImpl.java @@ -1,8 +1,14 @@ package com.hai.service.pay.impl; -import com.alibaba.fastjson.JSONObject; import com.hai.common.pay.entity.OrderType; import com.hai.common.utils.SpringContextUtil; +import com.hai.entity.HighChildOrder; +import com.hai.entity.HighOrder; +import com.hai.entity.HighUser; +import com.hai.enum_type.GoodsType; +import com.hai.enum_type.PayType; +import com.hai.service.HighOrderService; +import com.hai.service.HighUserService; import com.hai.service.pay.NotifyService; import com.hai.service.pay.PayRecordService; import com.hai.service.pay.PayService; @@ -22,6 +28,12 @@ public class NotifyServiceImpl implements NotifyService { @Resource private PayRecordService payRecordService; + @Resource + private HighOrderService highOrderService; + + @Resource + private HighUserService highUserService; + @Override @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public String alipayNotify(Map params) throws Exception { @@ -116,4 +128,5 @@ public class NotifyServiceImpl implements NotifyService { return payService; } + } diff --git a/hai-service/src/main/resources/dev/commonConfig.properties b/hai-service/src/main/resources/dev/commonConfig.properties index 681a182f..52a935fe 100644 --- a/hai-service/src/main/resources/dev/commonConfig.properties +++ b/hai-service/src/main/resources/dev/commonConfig.properties @@ -23,4 +23,5 @@ wx_cert=/home/project/wx_cert/ TelApiKey=2d01f6b520254b1a80f6b167832cea18 TelApiSecret=d11ee9b41e014a039f030e53ae6f5295 -TelMemberId=d13091df65d64aafbf0f35d2093157b7 \ No newline at end of file +TelMemberId=d13091df65d64aafbf0f35d2093157b7 +