|  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.ICommonService; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.model.LaKaLaBasicReqDate; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.model.LaKaLaCreateOrderReqDate; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.model.LaKaLaQueryOrderReqDate; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.service.LaKaLaService; | 
|---|
|  |  |  | import cc.mrbird.febs.rabbit.producter.AgentProducer; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUtil; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static final String appid = "OP00000418"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final String appid_prd = "OP00000418"; | 
|---|
|  |  |  | public static final String appid_prd = "OP00000671"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 商户证书序列号,和商户私钥对应 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static final String mchSerialNo = "01848940fd41"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final String mchSerialNo_prd = "01848940fd41"; | 
|---|
|  |  |  | public static final String mchSerialNo_prd = "018804e5ecd9"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 商户号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static final String merchant_no = "8222900701107M5"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final String merchant_no_prd = "8222900701107M5"; | 
|---|
|  |  |  | public static final String merchant_no_prd = "822301053110LXS"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 商户证书私钥,用于请求签名 | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static final String lklCertificatePathName = "classpath:lkl/lkl-apigw-v2.cer"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final String lklCertificatePathName_prd = "classpath:lkl/prd/lkl-apigw-v2.cer"; | 
|---|
|  |  |  | public static final String lklCertificatePathName_prd = "classpath:lkl/prd/lkl-apigw-v1.cer"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * api请求地址 | 
|---|
|  |  |  | 
|---|
|  |  |  | public final static String apiUrlCreate = "https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public final static String apiUrlCreate_prd = "https://s2.lakala.com/api/v3/ccss/counter/order/create"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public final static String apiUrlQuery = "https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/query"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public final static String apiUrlQuery_prd = "https://s2.lakala.com/api/v3/ccss/counter/order/query"; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 支付回调地址 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String body = JSONUtil.parseObj(laKaLaBasicReqDate).toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log.info("LKL创建请求Body,{}",body); | 
|---|
|  |  |  | String authorization = getAuthorization(body); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String apiUrlCreateHttp = ""; | 
|---|
|  |  |  | 
|---|
|  |  |  | String responseStr = IOUtils.toString(response.getEntity().getContent(), ENCODING); | 
|---|
|  |  |  | System.out.println("responseStr  " + responseStr); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log.info("LKL创建请求返回的responseStr,{}",responseStr); | 
|---|
|  |  |  | String source = appid + "\n" + lklapiSerial + "\n" + timestamp + "\n" + nonce + "\n" + responseStr + "\n"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | System.out.println("source  " + source); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public String payCallback(JSONObject jsonObject) { | 
|---|
|  |  |  | boolean flag = false; | 
|---|
|  |  |  | String orderStatus = jsonObject.get("order_status").toString(); | 
|---|
|  |  |  | if(2 != Integer.parseInt(orderStatus)){ | 
|---|
|  |  |  | return "FAIL"; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String orderNo = jsonObject.get("out_order_no").toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LambdaQueryWrapper<MallOrderInfo> query = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | query.eq(MallOrderInfo::getOrderNo, orderNo); | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.orderInfoMapper.selectOne(query); | 
|---|
|  |  |  | if ("1".equals(orderInfo.getPayResult())) { | 
|---|
|  |  |  | return "SUCCESS"; | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | {"req_time":"1660205634885","version":"3.0","req_data":{"out_order_no":"GHSNVDY8033038232443530","merchant_no":"8222900701107M5"}} | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LaKaLaQueryOrderReqDate laKaLaQueryOrderReqDate = new LaKaLaQueryOrderReqDate(); | 
|---|
|  |  |  | laKaLaQueryOrderReqDate.setOut_order_no(orderNo); | 
|---|
|  |  |  | if ("dev".equals(active) || "test".equals(active)) { | 
|---|
|  |  |  | laKaLaQueryOrderReqDate.setMerchant_no(merchant_no); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | laKaLaQueryOrderReqDate.setMerchant_no(merchant_no_prd); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); | 
|---|
|  |  |  | orderInfo.setPayResult("1"); | 
|---|
|  |  |  | orderInfo.setPayTime(new Date()); | 
|---|
|  |  |  | String payOrderNo = jsonObject.get("pay_order_no").toString(); | 
|---|
|  |  |  | orderInfo.setPayTradeNo(payOrderNo); | 
|---|
|  |  |  | orderInfoMapper.updateById(orderInfo); | 
|---|
|  |  |  | String yyyyMMddHHmmss = DateUtil.format(new Date(), "yyyyMMddHHmmss"); | 
|---|
|  |  |  | LaKaLaBasicReqDate laKaLaBasicReqDate = new LaKaLaBasicReqDate(); | 
|---|
|  |  |  | laKaLaBasicReqDate.setReq_time(yyyyMMddHHmmss); | 
|---|
|  |  |  | laKaLaBasicReqDate.setVersion("3.0"); | 
|---|
|  |  |  | JSONObject jsonObjectQuery = JSONUtil.parseObj(laKaLaQueryOrderReqDate); | 
|---|
|  |  |  | laKaLaBasicReqDate.setReq_data(jsonObjectQuery); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String body = JSONUtil.parseObj(laKaLaBasicReqDate).toString(); | 
|---|
|  |  |  | log.info("LKL查询请求Body,{}",body); | 
|---|
|  |  |  | String authorization = getAuthorization(body); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | commonService.changeWallet(orderInfo.getId(), FlowTypeEnum.WECHAT.getValue()); | 
|---|
|  |  |  | String apiUrlCreateHttp = ""; | 
|---|
|  |  |  | if ("dev".equals(active) || "test".equals(active)) { | 
|---|
|  |  |  | apiUrlCreateHttp = apiUrlQuery; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | apiUrlCreateHttp = apiUrlQuery_prd; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | HttpResponse response = post(apiUrlCreateHttp , body, authorization); | 
|---|
|  |  |  | if (response.getStatusLine().getStatusCode() != 200) { | 
|---|
|  |  |  | return "FAIL"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 插入一条待处理记录 | 
|---|
|  |  |  | * mq处理之后,更新状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | MallMqRecord mallMqRecord = new MallMqRecord(); | 
|---|
|  |  |  | mallMqRecord.setOrderId(orderInfo.getId()); | 
|---|
|  |  |  | mallMqRecord.setState(2); | 
|---|
|  |  |  | mallMqRecord.setRetryTimes(2); | 
|---|
|  |  |  | mallMqRecordMapper.insert(mallMqRecord); | 
|---|
|  |  |  | //发送补贴消息 | 
|---|
|  |  |  | agentProducer.sendPerkMoneyMsg(orderInfo.getId()); | 
|---|
|  |  |  | //发送代理自动升级消息 | 
|---|
|  |  |  | agentProducer.sendAutoLevelUpMsg(orderInfo.getMemberId()); | 
|---|
|  |  |  | String appid = getHeadValue(response, "Lklapi-Appid"); | 
|---|
|  |  |  | String lklapiSerial = getHeadValue(response, "Lklapi-Serial"); | 
|---|
|  |  |  | String timestamp = getHeadValue(response, "Lklapi-Timestamp"); | 
|---|
|  |  |  | String nonce = getHeadValue(response, "Lklapi-Nonce"); | 
|---|
|  |  |  | String signature = getHeadValue(response, "Lklapi-Signature"); | 
|---|
|  |  |  | String responseStr = IOUtils.toString(response.getEntity().getContent(), ENCODING); | 
|---|
|  |  |  | System.out.println("responseStr  " + responseStr); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return "SUCCESS"; | 
|---|
|  |  |  | log.info("LKL查询返回的responseStr,{}",responseStr); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String source = appid + "\n" + lklapiSerial + "\n" + timestamp + "\n" + nonce + "\n" + responseStr + "\n"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | System.out.println("source  " + source); | 
|---|
|  |  |  | String lklCertificatePathNameStr = ""; | 
|---|
|  |  |  | if ("dev".equals(active) || "test".equals(active)) { | 
|---|
|  |  |  | lklCertificatePathNameStr = lklCertificatePathName; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | lklCertificatePathNameStr = lklCertificatePathName_prd; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | InputStream fileInputStream = resourceLoader.getResource(lklCertificatePathNameStr).getInputStream(); | 
|---|
|  |  |  | X509Certificate lklCertificate = loadCertificate(fileInputStream); | 
|---|
|  |  |  | boolean verify = verify(lklCertificate, source.getBytes(ENCODING), signature); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (verify) { | 
|---|
|  |  |  | System.out.println("验签成功"); | 
|---|
|  |  |  | JSONObject parseObj = JSONUtil.parseObj(responseStr); | 
|---|
|  |  |  | String code = parseObj.get("code").toString(); | 
|---|
|  |  |  | if("000000".equals(code)){ | 
|---|
|  |  |  | Object respData = parseObj.get("resp_data"); | 
|---|
|  |  |  | JSONObject respDataChild = JSONUtil.parseObj(respData); | 
|---|
|  |  |  | String orderStatusQuery = respDataChild.get("order_status").toString(); | 
|---|
|  |  |  | if(2 != Integer.parseInt(orderStatusQuery)){ | 
|---|
|  |  |  | return "FAIL"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String tradeStatus = respDataChild.getJSONArray("order_trade_info_list").getJSONObject(0).get("trade_status").toString(); | 
|---|
|  |  |  | if(!"S".equals(tradeStatus)){ | 
|---|
|  |  |  | return "FAIL"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(flag){ | 
|---|
|  |  |  | LambdaQueryWrapper<MallOrderInfo> query = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | query.eq(MallOrderInfo::getOrderNo, orderNo); | 
|---|
|  |  |  | MallOrderInfo orderInfo = this.orderInfoMapper.selectOne(query); | 
|---|
|  |  |  | if ("1".equals(orderInfo.getPayResult())) { | 
|---|
|  |  |  | return "SUCCESS"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); | 
|---|
|  |  |  | orderInfo.setPayResult("1"); | 
|---|
|  |  |  | orderInfo.setPayTime(new Date()); | 
|---|
|  |  |  | String payOrderNo = jsonObject.get("pay_order_no").toString(); | 
|---|
|  |  |  | orderInfo.setPayTradeNo(payOrderNo); | 
|---|
|  |  |  | orderInfoMapper.updateById(orderInfo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | commonService.changeWallet(orderInfo.getId(), FlowTypeEnum.WECHAT.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 插入一条待处理记录 | 
|---|
|  |  |  | * mq处理之后,更新状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | MallMqRecord mallMqRecord = new MallMqRecord(); | 
|---|
|  |  |  | mallMqRecord.setOrderId(orderInfo.getId()); | 
|---|
|  |  |  | mallMqRecord.setState(2); | 
|---|
|  |  |  | mallMqRecord.setRetryTimes(2); | 
|---|
|  |  |  | mallMqRecordMapper.insert(mallMqRecord); | 
|---|
|  |  |  | //发送补贴消息 | 
|---|
|  |  |  | agentProducer.sendPerkMoneyMsg(orderInfo.getId()); | 
|---|
|  |  |  | //发送代理自动升级消息 | 
|---|
|  |  |  | agentProducer.sendAutoLevelUpMsg(orderInfo.getMemberId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return "SUCCESS"; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return "FAIL"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * {"req_time":"20221026100323", | 
|---|
|  |  |  | * "version":"1.0", | 
|---|
|  |  |  | * "req_data":{ | 
|---|
|  |  |  | *      "out_order_no":"GHSNVDY8033038232443530", | 
|---|
|  |  |  | *      "merchant_no":"8222900701107M5", | 
|---|
|  |  |  | *      "total_amount":1, | 
|---|
|  |  |  | *      "order_efficient_time":"20221118220823", | 
|---|
|  |  |  | *      "notify_url":"", | 
|---|
|  |  |  | *      "support_cancel":0, | 
|---|
|  |  |  | *      "support_refund":1, | 
|---|
|  |  |  | *      "support_repeat_pay":1, | 
|---|
|  |  |  | *      "order_info":"测试"}} | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | LaKaLaCreateOrderReqDate laKaLaCreateOrderReqDate = new LaKaLaCreateOrderReqDate(); | 
|---|
|  |  |  | laKaLaCreateOrderReqDate.setOut_order_no("GHSNVDY8033038232443530"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LaKaLaBasicReqDate laKaLaBasicReqDate = new LaKaLaBasicReqDate(); | 
|---|
|  |  |  | laKaLaBasicReqDate.setReq_time(DateUtil.format(new Date(),"yyyyMMddHHmmss")); | 
|---|
|  |  |  | laKaLaBasicReqDate.setVersion("3.0"); | 
|---|
|  |  |  | JSONObject jsonObject = JSONUtil.parseObj(laKaLaCreateOrderReqDate); | 
|---|
|  |  |  | laKaLaBasicReqDate.setReq_data(jsonObject); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String s = "{\n" + | 
|---|
|  |  |  | "    \"code\":\"000000\",\n" + | 
|---|
|  |  |  | "    \"msg\":\"操作成功\",\n" + | 
|---|
|  |  |  | "    \"resp_time\":\"20230419151705\",\n" + | 
|---|
|  |  |  | "    \"resp_data\":{\n" + | 
|---|
|  |  |  | "        \"merchant_no\":\"8222900701107M5\",\n" + | 
|---|
|  |  |  | "        \"channel_id\":\"95\",\n" + | 
|---|
|  |  |  | "        \"out_order_no\":\"HLM20230419151704\",\n" + | 
|---|
|  |  |  | "        \"order_create_time\":\"20230419151705\",\n" + | 
|---|
|  |  |  | "        \"order_efficient_time\":\"20230419161704\",\n" + | 
|---|
|  |  |  | "        \"pay_order_no\":\"23041911012001101011000965837\",\n" + | 
|---|
|  |  |  | "        \"total_amount\":\"1\",\n" + | 
|---|
|  |  |  | "        \"counter_url\":\"http://q.huijingcai.top/r/0000?pageStyle%3DV2%26token%3DCCSSIZlwnaqWmBw3FHY5U40nGcX7pxoKuxVhhVI7XyulHEUboR1I0VTIqJRMAjgj3IjCMWvoWjp9%2BXHpkA%3D%3D%26amount%3D1%26payOrderNo%3D23041911012001101011000965837\"\n" + | 
|---|
|  |  |  | "    }\n" + | 
|---|
|  |  |  | "}"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String s = "{\"code\":\"000000\"," + | 
|---|
|  |  |  | "\"msg\":\"操作成功\"," + | 
|---|
|  |  |  | "\"resp_time\":\"20230510154634\"," + | 
|---|
|  |  |  | "\"resp_data\":{\"pay_order_no\":\"23051011012001101011000969911\"," + | 
|---|
|  |  |  | "\"out_order_no\":\"2023051015455302379\"," + | 
|---|
|  |  |  | "\"channel_id\":\"95\"," + | 
|---|
|  |  |  | "\"trans_merchant_no\":\"8222900701107M5\"," + | 
|---|
|  |  |  | "\"trans_term_no\":\"A1062976\"," + | 
|---|
|  |  |  | "\"merchant_no\":\"8222900701107M5\"," + | 
|---|
|  |  |  | "\"term_no\":\"A1062976\"," + | 
|---|
|  |  |  | "\"order_status\":\"2\"," + | 
|---|
|  |  |  | "\"order_info\":\"礼包一\"," + | 
|---|
|  |  |  | "\"total_amount\":1," + | 
|---|
|  |  |  | "\"order_create_time\":\"20230510154556\"," + | 
|---|
|  |  |  | "\"order_efficient_time\":\"20230510164555\"," + | 
|---|
|  |  |  | "\"settle_type\":\"0\"," + | 
|---|
|  |  |  | "\"split_mark\":\"\"," + | 
|---|
|  |  |  | "\"counter_param\":null," + | 
|---|
|  |  |  | "\"counter_remark\":null," + | 
|---|
|  |  |  | "\"busi_type_param\":\"\"," + | 
|---|
|  |  |  | "\"sgn_info\":[]," + | 
|---|
|  |  |  | "\"goods_mark\":\"\"," + | 
|---|
|  |  |  | "\"goods_field\":\"\"," + | 
|---|
|  |  |  | "\"order_trade_info_list\":[{\"trade_no\":\"2023051066210308370172\"," + | 
|---|
|  |  |  | "\"log_No\":\"66210308370172\"," + | 
|---|
|  |  |  | "\"trade_ref_no\":\"\"," + | 
|---|
|  |  |  | "\"trade_type\":\"PAY\"," + | 
|---|
|  |  |  | "\"trade_status\":\"S\"," + | 
|---|
|  |  |  | "\"trade_amount\":1,\"payer_amount\":1,\"user_id1\":\"oLvoQ5W-MMaepM5fIf2XGOkatAzQ\",\"user_id2\":\"oUpF8uPxTeOlCA4eunIiiK6vZ9IA\",\"busi_type\":\"SCPAY\",\"trade_time\":\"20230510154610\",\"acc_trade_no\":\"4200001884202305101607494108\",\"payer_account_no\":\"\",\"payer_name\":\"\",\"payer_account_bank\":\"\",\"acc_type\":\"99\",\"pay_mode\":\"WECHAT\",\"client_batch_no\":\"\",\"client_seq_no\":\"\",\"settle_merchant_no\":\"8222900701107M5\",\"settle_term_no\":\"A1062976\",\"origin_trade_no\":\"\",\"auth_code\":\"\",\"bank_type\":\"OTHERS\"}]}}"; | 
|---|
|  |  |  | JSONObject parseObj = JSONUtil.parseObj(s); | 
|---|
|  |  |  | String code = parseObj.get("code").toString(); | 
|---|
|  |  |  | if("000000".equals(code)){ | 
|---|
|  |  |  | Object respData = parseObj.get("resp_data"); | 
|---|
|  |  |  | JSONObject respDataChild = JSONUtil.parseObj(respData); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Object respData = parseObj.get("resp_data"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONObject respDataChild = JSONUtil.parseObj(respData); | 
|---|
|  |  |  | String counterUrl = respDataChild.get("counter_url").toString(); | 
|---|
|  |  |  | System.out.println(counterUrl); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | System.out.println(respDataChild); | 
|---|
|  |  |  | //            String orderStatusQuery = respDataChild.get("order_status").toString(); | 
|---|
|  |  |  | String orderStatusQuery = respDataChild.get("order_trade_info_list").toString(); | 
|---|
|  |  |  | System.out.println(orderStatusQuery); | 
|---|
|  |  |  | String tradeStatus = respDataChild.getJSONArray("order_trade_info_list").getJSONObject(0).get("trade_status").toString(); | 
|---|
|  |  |  | System.out.println(tradeStatus); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public HttpResponse post(String url, String message, String authorization) throws Exception { | 
|---|