From f98946750a535c03520e2853bd9c6709fced3c27 Mon Sep 17 00:00:00 2001 From: YUANYE <418471657@qq.com> Date: Tue, 8 Jun 2021 14:46:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=88=86=E8=B4=A6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/pay/WechatPayController.java | 7 +- .../java/com/hai/common/utils/HttpsUtils.java | 85 +++++++++++++++--- .../java/com/hai/common/utils/WxUtils.java | 12 +++ .../java/com/hai/service/pay/PayService.java | 1 + .../main/java/privatekey/apiclient_cert.p12 | Bin 0 -> 2694 bytes .../main/java/privatekey/apiclient_cert.pem | 23 +++++ .../main/java/privatekey/apiclient_key.pem | 28 ++++++ 7 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 hai-service/src/main/java/privatekey/apiclient_cert.p12 create mode 100644 hai-service/src/main/java/privatekey/apiclient_cert.pem create mode 100644 hai-service/src/main/java/privatekey/apiclient_key.pem 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 633c89e5..65eebec9 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 @@ -163,12 +163,13 @@ public class WechatPayController { WxSharingReceiversVO receiversVO = new WxSharingReceiversVO(); receiversVO.setAccount("1609882817"); receiversVO.setType("MERCHANT_ID"); - receiversVO.setName("嗨加油"); + receiversVO.setName("个体户黎杨珍"); receiversVO.setRelation_type("SERVICE_PROVIDER"); Map map = new HashMap<>(); map.put("mch_id" , "1289663601"); + map.put("sub_mch_id" , "1609882817"); map.put("appid" , "wx637bd6f7314daa46"); map.put("nonce_str" , WxUtils.makeNonStr()); map.put("sign_type" , "HMAC-SHA256"); @@ -180,7 +181,7 @@ public class WechatPayController { String url = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver"; String xm = WxUtils.mapToXml(map); - String rest = HttpsUtils.postData(url, xm); + String rest = String.valueOf(HttpsUtils.postData(url, xm)); System.out.println(rest); log.info("微信支付 -> 添加分账接收方:处理开始"); @@ -189,4 +190,6 @@ public class WechatPayController { } } + + } diff --git a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java index 4be9e855..c36787c4 100644 --- a/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/HttpsUtils.java @@ -15,6 +15,7 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContexts; import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; @@ -29,10 +30,13 @@ import org.slf4j.LoggerFactory; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocketFactory; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.security.GeneralSecurityException; +import java.security.KeyStore; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; @@ -459,12 +463,13 @@ public class HttpsUtils { } /** - - * - * @param url API地址 - * @return - */ - public static String postData(String url, String str) { + * @Author Sum1Dream + * @Description // 不带证书请求xml + * @Date 11:42 2021/6/8 + * @Param [url, str] + * @return com.alibaba.fastjson.JSONObject + **/ + public static JSONObject postData(String url, String str) { CloseableHttpClient httpClient = null; if (url.startsWith("https")) { httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) @@ -480,13 +485,57 @@ public class HttpsUtils { httpPost.setConfig(requestConfig); StringEntity stringEntity = new StringEntity(str, "UTF-8");// 解决中文乱码问题 + stringEntity.setContentEncoding("UTF-8"); httpPost.addHeader("Content-Type", "text/xml"); httpPost.setEntity(stringEntity); + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + httpStr = EntityUtils.toString(entity, "UTF-8"); + return JSON.parseObject(httpStr); + } catch (Exception e) { + log.error(e.getMessage(),e); + } finally { + if (response != null) { + try { + EntityUtils.consume(response.getEntity()); + } catch (IOException e) { + log.error(e.getMessage(),e); + } + } + } + return null; + } - HttpResponse httpResponse = httpClient.execute(httpPost); - HttpEntity httpEntity = httpResponse.getEntity(); - return EntityUtils.toString(httpEntity, "UTF-8"); + /** + * @Author Sum1Dream + * @Description // 带证书请求 xml + * @Date 11:45 2021/6/8 + * @Param [url, mchId, str] + * @return com.alibaba.fastjson.JSONObject + **/ + public static JSONObject postData(String url, String mchId , String str) { + CloseableHttpClient httpClient = null; + if (url.startsWith("https")) { + httpClient = HttpClients.custom().setSSLSocketFactory(readCertificate(mchId)) + .setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); + } else { + httpClient = HttpClients.createDefault(); + } + String httpStr = null; + CloseableHttpResponse response = null; + try { + HttpPost httpPost = new HttpPost(url); + httpPost.setConfig(requestConfig); + + StringEntity stringEntity = new StringEntity(str, "UTF-8");// 解决中文乱码问题 + stringEntity.setContentEncoding("UTF-8"); + httpPost.addHeader("Content-Type", "text/xml"); + httpPost.setEntity(stringEntity); + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + httpStr = EntityUtils.toString(entity, "UTF-8"); + return JSON.parseObject(httpStr); } catch (Exception e) { log.error(e.getMessage(),e); } finally { @@ -501,7 +550,23 @@ public class HttpsUtils { return null; } - + public static SSLConnectionSocketFactory readCertificate(String mchId) { + try { + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + FileInputStream stream = new FileInputStream( "F:/mine/hai-server/hai-service/src/main/java/privatekey/apiclient_cert.p12"); + keyStore.load(stream , mchId.toCharArray()); + stream.close(); + SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mchId.toCharArray()).build(); + return new SSLConnectionSocketFactory( + sslcontext, + new String[]{"TLSv1"}, + null, + SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); + } catch (Exception e) { + System.out.println("证书双向认证出现异常" + e); + } + return null; + } /** * 创建SSL安全连接 diff --git a/hai-service/src/main/java/com/hai/common/utils/WxUtils.java b/hai-service/src/main/java/com/hai/common/utils/WxUtils.java index 10e70a06..f2d62f68 100644 --- a/hai-service/src/main/java/com/hai/common/utils/WxUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/WxUtils.java @@ -1,5 +1,6 @@ package com.hai.common.utils; +import com.alibaba.fastjson.JSON; import com.google.common.collect.Maps; import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.pay.util.sdk.WXPayXmlUtil; @@ -7,15 +8,23 @@ import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.naming.NoNameCoder; import com.thoughtworks.xstream.io.xml.XppDriver; import net.sf.cglib.beans.BeanMap; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContexts; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import java.io.File; +import java.io.FileInputStream; import java.io.StringWriter; +import java.security.KeyStore; import java.security.MessageDigest; import java.security.SecureRandom; import java.util.*; @@ -292,4 +301,7 @@ public class WxUtils { return output; } + + + } diff --git a/hai-service/src/main/java/com/hai/service/pay/PayService.java b/hai-service/src/main/java/com/hai/service/pay/PayService.java index f3b47bf1..c9345b8a 100644 --- a/hai-service/src/main/java/com/hai/service/pay/PayService.java +++ b/hai-service/src/main/java/com/hai/service/pay/PayService.java @@ -18,4 +18,5 @@ public interface PayService { */ void paySuccess(Map map, String payType) throws Exception; + } diff --git a/hai-service/src/main/java/privatekey/apiclient_cert.p12 b/hai-service/src/main/java/privatekey/apiclient_cert.p12 new file mode 100644 index 0000000000000000000000000000000000000000..54e86e504919e57e505ef4689d664a94579b72a7 GIT binary patch literal 2694 zcmY+Ec{~#iAICSgvAM;_$T?TT94*HbjSNYSkfG#iY(nm6TF#Z3xeB?95FtlWNv`E6 zXQG6nTuE|YkKgO{JWtQ_$LIBZeczw&>-*;$O@&d}fb3{0>Ha1Q` z6cyxGe#?#H_t=ixm#&v(Ir`sO#ABf6(D{zO+_fHAe5-#ziw?b7?VQF8Jn1JAzLAwV zX=|cDp}>h*oJrtfoweXUPi-|Db{k@qIy%vOE;?49o4+ueMnc^*f(=Ez__IH2!}7L^ zr_?}o3r}i0KIV8&Qu#cp-^N>fYh3GjeeRe^KEEkf-GG< zZrHJQ<4JQaS5tDIowkf?$WV@ns`bo@JTPdoP9`G7j)we}wrRT7LZ}qgi>!y&zza>C zcw;6CLN4hsh6IFIA)FBufh_^y587 zIb9Y}sQnhCm~Pj>*T4}S)0{!yg;98?MQm;vz4;RqL!!Lh|GwL z*t6tNF}OpMqQbGB6+uYN$Jt!@8q>TKx*b%%#Zh=j>(zixJSstZQDmqU<3oboC_Vq) zh9D&{w$59{ja%^+%n;HcX%Y z?qLCE5sk*Qa<6P>1<$hNOf$(dX@i4~mPd})%}%nf=c47&xew59uM>yRf8v^5Q{{8= zMCd<8!NFW|!zK$YIa#iIm!2heGOwptiW7VXdVr@qrY2{SUOW9aA+bV-$>9sIJ_1g_fb{2&AR0m&V= zFP*!HDK)Awfydl(E|0WzX;B4)YkO_jLM+se1#jBW_JtZ^(>x`kh>HZqjGLM_-(8$& zQLX0~kJ%$Ny4MG|tR=~%abDPFvC91h!mKwn%2?;69@5%=Vs%NfQuulenhFm7A3^0& z!CoLL*zEvcJO}~8^&efqfNTd|`*|R=x&N~m`#%;7PxD>l6We9~$6_EVsPoTREo7`V zUhv+qYL{mE1<2}`$U>@N!KAXPp$3lu*Zh6u+kWh#_3er+r(ciU0}#!D^~oIx?&A@= za`PyJv7Yx%m0wL5rL1);6X#?7NTN#T&3mUU1yLVF*+dC z;*m?jC*9I5L#kl|zm+gAC#1y8IsGaiB5M5bV*b0o0$8m(xi>DcNoi;@H&4%wzB7nS zoCvwMmo)y-8)FG~e|k1X12~IS9og_TLgLQs7m0o2w@+g8jV#|t{F=iYzD1L9#IlH} zT*LZn(hb(=`Wi-hZ`~GFeP4_Jjs$7U|0`9|CG1wa0&<;Uxr+jCMJbhRjBMi(+UbAJ zxESJ-8S+_oJMH$BVjuVCHthc?vNer3TKS0{Zy#YHu(-;k2v)5p zjzf01)5jaAA1{tv?ce)-9mzGEVzzq%W|!g}X2H8?g2E_bbAMDd)xpj;(V~=0SHG$* zEH|0)_VRe*g-`stY$*`Rp?s<$TG;r;1om89_+0$$#78YmfP*s4-PPKMtH&(uG#N^& z+zM%-5fzHxf?ufmR9vWyX+1$#3#i`SFkZvo8)52?Z=G~K8joq8(Vh-!=!(Qek&s_L z0vrlZ_6+3pNVfu>HtYqGs_!@4(S*vJK_R-;NAlowMs!hW0rZ14dz{gllb9J;GMtvRw(Z4QCkTl}Z-`$BoI&{Ev*5YB2&pPo zg~o+94}1l^zi%o5g(;@IQ%MtS&t88We0kO5q!!}J`@;+s%!930*qC84#Ei(z(fW|! zxvW6ZjuI9oi_qh(4*GL!muk!%(EYS)tjg$!&_Zs zKclB#H>8PbJc|gciC9yv($IZFPzlnD3>BAe*-rz9_8bDGI|_>U@qyy?iq507-0-`6 zJ(VDGSfstKLni6b1KNjFA$71kxja2qZib40-uH%tabQp@>iQl|yXhjp8CIiC=0 zO@DoIT;|kb^vsBjlPE&^iReQE;^Q0^#5+gZ`u9k8{FphMmTRZg{Tm55nc~Lr zV>VAM^3Mlf@)-)mwk6L+u)5V9(X#)wBUD%&4iajVT8j@wf9PLcLYiFbC@6;b#|fb| z{~igc%O8;g*aAENz5qXfDwUeIz@MetR{WCb(l=bU Date: Wed, 9 Jun 2021 01:15:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?'=E8=B0=83=E9=80=9A=E5=88=86=E8=B4=A6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cweb/controller/pay/OrderController.java | 4 +- .../controller/pay/WechatPayController.java | 156 +++++++++++++++++- .../privatekey/1289663601_apiclient_cert.p12 | Bin 0 -> 2710 bytes .../privatekey/1604968055_apiclient_cert.p12 | Bin 0 -> 2694 bytes .../common/pay/entity/WeChatPayReqInfo.java | 9 + .../java/com/hai/common/utils/HttpsUtils.java | 39 +++++ 6 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 hai-cweb/src/main/resources/privatekey/1289663601_apiclient_cert.p12 create mode 100644 hai-cweb/src/main/resources/privatekey/1604968055_apiclient_cert.p12 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 1ba43b8d..f8bc160b 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 @@ -160,7 +160,9 @@ public class OrderController { weChatPayReqInfo.setSpbill_create_ip("139.159.177.244"); //终端ip weChatPayReqInfo.setNotify_url(SysConst.getSysConfig().getNotifyUrl()); //通知url weChatPayReqInfo.setTrade_type("JSAPI"); //交易类型 - weChatPayReqInfo.setAttach(map.get("orderScene").toString()); //附加数据,区分订单类型 + weChatPayReqInfo.setAttach(map.get("orderScene").toString()); + weChatPayReqInfo.setProfit_sharing("Y"); + //附加数据,区分订单类型 Map payMap = new HashMap<>(); payMap.put("app_id",SysConst.getSysConfig().getWxSubAppId()); 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 65eebec9..68168b7a 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 @@ -1,29 +1,51 @@ package com.cweb.controller.pay; import com.alibaba.fastjson.JSONObject; +import com.cweb.config.SysConst; import com.hai.common.pay.WechatPayUtil; import com.hai.common.pay.util.IOUtil; import com.hai.common.pay.util.XmlUtil; 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.SecRegion; +import com.hai.model.ResponseData; import com.hai.model.WxSharingOrderRequestModel; import com.hai.model.WxSharingReceiversVO; import com.hai.service.pay.NotifyService; import com.hai.service.pay.PayRecordService; +import com.wechat.pay.contrib.apache.httpclient.util.PemUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import net.sf.cglib.beans.BeanMap; +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.stereotype.Controller; 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.ResponseBody; import javax.annotation.Resource; +import javax.net.ssl.SSLContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.BufferedOutputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.UnsupportedEncodingException; +import java.security.*; import java.util.*; @Controller @@ -155,15 +177,113 @@ public class WechatPayController { return key; }*/ + + @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) + @ApiOperation(value = "微信分账") + @ResponseBody + public ResponseData wxProfitsharing() { + try { + Map param = new LinkedHashMap<>(); + param.put("appid", "wx637bd6f7314daa46"); + param.put("mch_id", "1289663601"); + param.put("sub_mch_id" , "1609882817"); + param.put("transaction_id" , "4200001152202106091959467542"); + param.put("out_order_no" , "HF2021060901121681200"); + param.put("nonce_str" , WxUtils.makeNonStr()); + + List> receiversList = new ArrayList<>(); + Map receiversMap = new LinkedHashMap<>(); + receiversMap.put("type", "MERCHANT_ID"); + receiversMap.put("account", "1603942866"); + receiversMap.put("amount", 1); + receiversMap.put("description", "分给1603942866商户"); + //receiversMap.put("name", "个体户黎杨珍"); + receiversList.add(receiversMap); + param.put("receivers" , JSONObject.toJSONString(receiversList)); + + String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); + param.put("sign" , signStr); + + /*String certPath = "/path/to/apiclient_cert.p12"; + + String post = getToken("POST", "/v3/pay/transactions/h5", JSONObject.toJSONString(param)); + + Map header = new HashMap<>(); + header.put("Accept","application/json"); + header.put("Authorization", "WECHATPAY2-SHA256-RSA2048 " + post);*/ + + //JSONObject object = HttpsUtils.doWxPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing", param, header); + + //String url = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing"; + String xm = WxUtils.mapToXml(param); + // String rest = String.valueOf(HttpsUtils.postData(url, xm)); + return ResponseMsgUtil.success(this.doRefundRequest(param.get("mch_id"),null, xm)); + // return ResponseMsgUtil.success(null); + + } catch (Exception e) { + log.error("CmsContentController --> getCorporateAdvertising() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + //微信小程序读取双向证书 + private static CloseableHttpClient readCertificate(String mchId) throws Exception{ + /** + * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 + */ + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 + FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-cweb/src/main/resources/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(); + } + } + @RequestMapping(value = "/addLedgerReceiver", method = RequestMethod.POST) @ApiOperation(value = "微信支付 -> 添加分账接收方") public void addLedgerReceiver(HttpServletRequest request, HttpServletResponse response) { try { WxSharingReceiversVO receiversVO = new WxSharingReceiversVO(); - receiversVO.setAccount("1609882817"); + receiversVO.setAccount("1603942866"); receiversVO.setType("MERCHANT_ID"); - receiversVO.setName("个体户黎杨珍"); + receiversVO.setName("重庆惠昕石化有限责任公司"); receiversVO.setRelation_type("SERVICE_PROVIDER"); Map map = new HashMap<>(); @@ -191,5 +311,37 @@ public class WechatPayController { } + String getToken(String method, String url, String body) throws UnsupportedEncodingException, SignatureException, NoSuchAlgorithmException, InvalidKeyException, FileNotFoundException { + + long timeMillis = System.currentTimeMillis(); + String nonceStr = String.valueOf(timeMillis); + long timestamp = System.currentTimeMillis() / 1000; + String message = buildMessage(method, url, timestamp, nonceStr, body); + PrivateKey privateKey = PemUtil.loadPrivateKey(new FileInputStream("G:/hurui-project/hai-parent/hai-cweb/src/main/resources/privatekey/apiclient_key.pem")); + String signature = sign(privateKey,message.getBytes("utf-8")); + + return "mchid=\"" + SysConst.getSysConfig().getWxSubMchId() + "\"," + + "nonce_str=\"" + nonceStr + "\"," + + "timestamp=\"" + timestamp + "\"," + + "serial_no=\"" + "1B08DC2A078B0B1F77A65C97C445AAD545B5EAA6" + "\"," + + "signature=\"" + signature + "\""; + } + + String sign(PrivateKey privateKey,byte[] message) throws SignatureException, NoSuchAlgorithmException, InvalidKeyException { + Signature sign = Signature.getInstance("SHA256withRSA"); + sign.initSign(privateKey); + sign.update(message); + return Base64.getEncoder().encodeToString(sign.sign()); + } + + String buildMessage(String method, String url, long timestamp, String nonceStr, String body) { + return method + "\n" + + url + "\n" + + timestamp + "\n" + + nonceStr + "\n" + + body + "\n"; + } + + } diff --git a/hai-cweb/src/main/resources/privatekey/1289663601_apiclient_cert.p12 b/hai-cweb/src/main/resources/privatekey/1289663601_apiclient_cert.p12 new file mode 100644 index 0000000000000000000000000000000000000000..1bb73687ca12962f6a25417017463a8ea189dacb GIT binary patch literal 2710 zcmY+^c{~(~76Br{`|s8kPKE9HaH35zyX$jc=O@TDHcu^ zG6`Y=BtZ;L;u~-huL@8S^Hi|f zD%bBvv+YK{A)LsZ4yI#97*o-yQO_GsPLx9|<%DcEf91S<4bqzO%fPWGMNK;|Qg?o3 zGcLlsH!0rcpd~j}uzuIw4HYJlSUEw(9`1j$m#J{QYd|9VpLsISJzy8Kq~ zYdcKUxf09s>NH0c5r$D?-P<%N5d%g}x2xRzakPf1>*@<31v7{GjX7xVKAz_1c{m=Z zViX)A%*U7>uc`PNE+r50@*Cr(t^$@cw8|#6IgNK)F)sF@e@dB#Ubu#0goKCHnc>y3 zVq-QFXYR(TZs$UeVp&Z09|WNt*3q4YUXz(W>adAKLfMp)!kxUSOY##$axnpCSjj2l zui-4$&(9cen>_QxOZhx8-VUW?)seN7tZU}fzNl2~1&=PxO1ex+FHXJ3>q^D-hCPpB zLUm!EJbcJc_b~O%p`%sdq!s4S$in0GM)J{4buq5Te_!M=KQH)T&(TCJh~qAsNZhA2 z2~L6E#1sKvntUgpO$Qaw!mRKjQ_+>p{BIoIsZDRVcq2cMo}Z zEh@~JXsHO8iVoupAv#2uD~e2RPjlqycj}j+2yXcU+Xhdnb}A=8ywyE;^9RkAN#0(s z%I7pm?{^v}m?ge+@3F^X--cNHwx4BM4x4jOoVeFw6}5HD_mgURmvshH2u3|0et$Ib zEFLPk*+a!0s(-IO6;GkZh;$8%*J!;~LA4604Xl`-&2xE3`);Kmb*_#?v6JgEXs~;z zzSbPDGm{}4AsmjlDy@FQrFlXS@MUa_^9_P0RJNeY^eD3Cz4LJa-AZ#qrd8CMUBG^E zcRgynt&{75h9NAyVxh=*z|laYtEFQ@+U{(WuRQQ7T1Uv&om;r>t!wzedA!N2>DxR_ zA?=8Ci4Cbj8-ts>)!DUg!zPUfz(f@Wm+(LD{q)sk z;}^mI@JIotVV3j_3f@!>Fg+s+S1F_IvcP^>M)9GA%LD@kIUpAei>_>cDyNUcB=Zw0 z;&@`HsaG-zP|Ny8q)DeV!^{vWW&Bz7E-#O`(yJDrq02iJf2g0QfjIJbEM+}i)C#`d>r z;^GVa((|b|{#Ff00#ZkopMLFVVm#_9Q?aEUXhOCSMTr|6a(`Mp#_awW4*G@k=6ad7 z%57rQO?DhP=g(NvwUZM30oDn?V2CeH+1$D@9(hG-Uvl^6yb^XfW666Y+c86cgupD4NINNsLy~m5*NQC+l1=X2>dIQcw^h%aT=Z%_Q){FPc`B* zV@Wn>*;&gXY1|;D$o3a|H86A3tmV&c`or5>>|r$(=Aa3>w)!`Z@&a6ys zOhT-)u9Df{+~OZazMI@xOKS}&tF+dIw9~my@tn<-1Mdpld1N3o6}o`pYsWnCw0OJb2i~ap{~l; zOD|{o7m@{c3XI#kTNbA9+lwOkgnV-rMshaN5!!0V(K3DWGX%YfX>ADK|8Y6KcbHhYeZ>!X@+SKj>8NfZC&g72TOF!a7+63K;A`X z*!K4px6nCk$f9*$?Bj`9AEpL|4Qp9z%|C_}EmW&m6D5_K1QJ_5T6*19`$#x0~%-{qh<6Z0Z3gwt!?-YK`6 zouOj&Or{f1b5D1Pl`(`5nEMdD;?u9XUKYzu_8-9^=PC6g=vKm(U0wOMDy8tC1(*_^ z?y!1|99bH@*QY2*9=nHMy?(A7x9`_i=7fh`y${Kc{%Q#Q?w=V5>PI#DNtCJ$R#vZ$ zhaHa0A-e_aswp?X*N;6U6GGd{<~w9H_6e-z!>_19aIOzTqvEQO5=uGR!oECS@idRv zN{=j)ws6nj^q;$Tfag1Ro#;C5~5H8B<|{hT1LE@Sv)A9y`WhYIJFwpFI) zCKyH_6^@8W_a5|P+K;hOV)w-zO#&cJ<|yWC>C&y+vH4aDp4LKNVsQOqzJW>|+4qV) zgQl#d5KctDlK6x}U$hNu1rWOG9ayWcW@1$U`|(HM#haqy)Ys8NZ{EuWlf;j}odK8b zWA1w9Hut_Ke(ao*$L;^`^$)M{;#@AzF@`hp%NANtnf1kC9#Q%sTTQH%=O+RSm-?@cU?@TmC@>P~ z)i{ro88<+s1)Qp;uhn|rd;wSf=STn{BPI>70(by?0e%1%Ko~#*pm#D60D%BJ;Lb_8 zouq*P54ZyS0vyc24m-`pdX60c6qtu4Key?O&Gc+TVJRU185>^4G7zLi{qY=neb)Cc DnO6n3 literal 0 HcmV?d00001 diff --git a/hai-cweb/src/main/resources/privatekey/1604968055_apiclient_cert.p12 b/hai-cweb/src/main/resources/privatekey/1604968055_apiclient_cert.p12 new file mode 100644 index 0000000000000000000000000000000000000000..54e86e504919e57e505ef4689d664a94579b72a7 GIT binary patch literal 2694 zcmY+Ec{~#iAICSgvAM;_$T?TT94*HbjSNYSkfG#iY(nm6TF#Z3xeB?95FtlWNv`E6 zXQG6nTuE|YkKgO{JWtQ_$LIBZeczw&>-*;$O@&d}fb3{0>Ha1Q` z6cyxGe#?#H_t=ixm#&v(Ir`sO#ABf6(D{zO+_fHAe5-#ziw?b7?VQF8Jn1JAzLAwV zX=|cDp}>h*oJrtfoweXUPi-|Db{k@qIy%vOE;?49o4+ueMnc^*f(=Ez__IH2!}7L^ zr_?}o3r}i0KIV8&Qu#cp-^N>fYh3GjeeRe^KEEkf-GG< zZrHJQ<4JQaS5tDIowkf?$WV@ns`bo@JTPdoP9`G7j)we}wrRT7LZ}qgi>!y&zza>C zcw;6CLN4hsh6IFIA)FBufh_^y587 zIb9Y}sQnhCm~Pj>*T4}S)0{!yg;98?MQm;vz4;RqL!!Lh|GwL z*t6tNF}OpMqQbGB6+uYN$Jt!@8q>TKx*b%%#Zh=j>(zixJSstZQDmqU<3oboC_Vq) zh9D&{w$59{ja%^+%n;HcX%Y z?qLCE5sk*Qa<6P>1<$hNOf$(dX@i4~mPd})%}%nf=c47&xew59uM>yRf8v^5Q{{8= zMCd<8!NFW|!zK$YIa#iIm!2heGOwptiW7VXdVr@qrY2{SUOW9aA+bV-$>9sIJ_1g_fb{2&AR0m&V= zFP*!HDK)Awfydl(E|0WzX;B4)YkO_jLM+se1#jBW_JtZ^(>x`kh>HZqjGLM_-(8$& zQLX0~kJ%$Ny4MG|tR=~%abDPFvC91h!mKwn%2?;69@5%=Vs%NfQuulenhFm7A3^0& z!CoLL*zEvcJO}~8^&efqfNTd|`*|R=x&N~m`#%;7PxD>l6We9~$6_EVsPoTREo7`V zUhv+qYL{mE1<2}`$U>@N!KAXPp$3lu*Zh6u+kWh#_3er+r(ciU0}#!D^~oIx?&A@= za`PyJv7Yx%m0wL5rL1);6X#?7NTN#T&3mUU1yLVF*+dC z;*m?jC*9I5L#kl|zm+gAC#1y8IsGaiB5M5bV*b0o0$8m(xi>DcNoi;@H&4%wzB7nS zoCvwMmo)y-8)FG~e|k1X12~IS9og_TLgLQs7m0o2w@+g8jV#|t{F=iYzD1L9#IlH} zT*LZn(hb(=`Wi-hZ`~GFeP4_Jjs$7U|0`9|CG1wa0&<;Uxr+jCMJbhRjBMi(+UbAJ zxESJ-8S+_oJMH$BVjuVCHthc?vNer3TKS0{Zy#YHu(-;k2v)5p zjzf01)5jaAA1{tv?ce)-9mzGEVzzq%W|!g}X2H8?g2E_bbAMDd)xpj;(V~=0SHG$* zEH|0)_VRe*g-`stY$*`Rp?s<$TG;r;1om89_+0$$#78YmfP*s4-PPKMtH&(uG#N^& z+zM%-5fzHxf?ufmR9vWyX+1$#3#i`SFkZvo8)52?Z=G~K8joq8(Vh-!=!(Qek&s_L z0vrlZ_6+3pNVfu>HtYqGs_!@4(S*vJK_R-;NAlowMs!hW0rZ14dz{gllb9J;GMtvRw(Z4QCkTl}Z-`$BoI&{Ev*5YB2&pPo zg~o+94}1l^zi%o5g(;@IQ%MtS&t88We0kO5q!!}J`@;+s%!930*qC84#Ei(z(fW|! zxvW6ZjuI9oi_qh(4*GL!muk!%(EYS)tjg$!&_Zs zKclB#H>8PbJc|gciC9yv($IZFPzlnD3>BAe*-rz9_8bDGI|_>U@qyy?iq507-0-`6 zJ(VDGSfstKLni6b1KNjFA$71kxja2qZib40-uH%tabQp@>iQl|yXhjp8CIiC=0 zO@DoIT;|kb^vsBjlPE&^iReQE;^Q0^#5+gZ`u9k8{FphMmTRZg{Tm55nc~Lr zV>VAM^3Mlf@)-)mwk6L+u)5V9(X#)wBUD%&4iajVT8j@wf9PLcLYiFbC@6;b#|fb| z{~igc%O8;g*aAENz5qXfDwUeIz@MetR{WCb(l=bU body, Map header) { + CloseableHttpClient httpClient = null; + if (apiUrl.startsWith("https")) { + httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) + .setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); + } else { + httpClient = HttpClients.createDefault(); + } + String httpStr = null; + CloseableHttpResponse response = null; + + try { + HttpPost httpPost = new HttpPost(apiUrl); + httpPost.setConfig(requestConfig); + for (Map.Entry entry : header.entrySet()) { + httpPost.setHeader(entry.getKey(), entry.getValue().toString()); + } + StringEntity stringEntity = new StringEntity(JSON.toJSONString(body), "UTF-8");// 解决中文乱码问题 + stringEntity.setContentEncoding("UTF-8"); + stringEntity.setContentType("application/json"); + httpPost.setEntity(stringEntity); + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + httpStr = EntityUtils.toString(entity, "UTF-8"); + return JSON.parseObject(httpStr); + } catch (Exception e) { + log.error(e.getMessage(),e); + } finally { + if (response != null) { + try { + EntityUtils.consume(response.getEntity()); + } catch (IOException e) { + log.error(e.getMessage(),e); + } + } + } + return null; + } + public static JSONObject doPost(String apiUrl, Map body, Map header) { CloseableHttpClient httpClient = null; if (apiUrl.startsWith("https")) { From bc9beddc90875fbe1dab3bcffbe111074de2c00f Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 9 Jun 2021 23:59:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?'=E5=AE=8C=E6=88=90=E5=88=86=E8=B4=A6'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/pay/WechatPayController.java | 180 +---- .../dao/HighProfitSharingRecordMapper.java | 110 +++ .../dao/HighProfitSharingRecordMapperExt.java | 7 + .../HighProfitSharingRecordSqlProvider.java | 276 +++++++ .../hai/entity/HighProfitSharingRecord.java | 178 +++++ .../HighProfitSharingRecordExample.java | 754 ++++++++++++++++++ .../com/hai/model/ResultProfitSharing.java | 98 +++ .../HighProfitSharingRecordService.java | 12 + .../HighProfitSharingRecordServiceImpl.java | 20 + .../pay/impl/GoodsOrderServiceImpl.java | 227 ++++-- 10 files changed, 1639 insertions(+), 223 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordMapper.java create mode 100644 hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordMapperExt.java create mode 100644 hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordSqlProvider.java create mode 100644 hai-service/src/main/java/com/hai/entity/HighProfitSharingRecord.java create mode 100644 hai-service/src/main/java/com/hai/entity/HighProfitSharingRecordExample.java create mode 100644 hai-service/src/main/java/com/hai/model/ResultProfitSharing.java create mode 100644 hai-service/src/main/java/com/hai/service/HighProfitSharingRecordService.java create mode 100644 hai-service/src/main/java/com/hai/service/impl/HighProfitSharingRecordServiceImpl.java 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 68168b7a..8310971e 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 @@ -3,6 +3,7 @@ package com.cweb.controller.pay; import com.alibaba.fastjson.JSONObject; import com.cweb.config.SysConst; import com.hai.common.pay.WechatPayUtil; +import com.hai.common.pay.entity.WechatCallBackInfo; import com.hai.common.pay.util.IOUtil; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; @@ -10,10 +11,12 @@ 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.model.ResponseData; import com.hai.model.WxSharingOrderRequestModel; import com.hai.model.WxSharingReceiversVO; +import com.hai.service.HighProfitSharingRecordService; import com.hai.service.pay.NotifyService; import com.hai.service.pay.PayRecordService; import com.wechat.pay.contrib.apache.httpclient.util.PemUtil; @@ -45,6 +48,7 @@ import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; import java.security.*; import java.util.*; @@ -64,6 +68,9 @@ public class WechatPayController { @Resource private WechatPayUtil wechatPayUtil; + @Resource + private HighProfitSharingRecordService highProfitSharingRecordService; + @RequestMapping(value = "/notify", method = RequestMethod.POST) @ApiOperation(value = "微信支付 -> 异步回调") public void wechatNotify(HttpServletRequest request, HttpServletResponse response) { @@ -102,179 +109,6 @@ public class WechatPayController { } } - /*@RequestMapping(value = "/testCreateOrder", method = RequestMethod.GET) - @ApiOperation(value = "微信测试 创建支付信息(发版时注释此接口)") - @ResponseBody - public SortedMap testCreateOrder(@RequestParam(value = "subject", required = true) String subject, - @RequestParam(value = "orderNo", required = true) String orderNo, - @RequestParam(value = "totalPrice", required = true) Integer totalPrice, - HttpServletRequest httpRequest, HttpServletResponse httpResponse) { - try { - String nonce_str = MD5Util.MD5Encode(String.valueOf(ThreadLocalRandom.current().nextInt(10000)), "UTF-8"); - WeChatPayReqInfo weChatPayReqInfo = new WeChatPayReqInfo(); - weChatPayReqInfo.setAppid(wechatConfig.getApp_id()); //公众号id - weChatPayReqInfo.setMch_id(wechatConfig.getMch_id()); //商户号 - weChatPayReqInfo.setNonce_str(nonce_str); //随机字符串 - weChatPayReqInfo.setBody(subject); //商品描述 - weChatPayReqInfo.setOut_trade_no(orderNo); //商户订单号 - weChatPayReqInfo.setTotal_fee(totalPrice); //总 - weChatPayReqInfo.setSpbill_create_ip("182.43.154.4"); //终端ip - weChatPayReqInfo.setNotify_url(wechatConfig.getNotify_url()); //通知url - //weChatPayReqInfo.setTrade_type("APP"); //交易类型 - weChatPayReqInfo.setTrade_type("JSAPI"); - //weChatPayReqInfo.setOpenid(""); - weChatPayReqInfo.setAttach("Test"); - - *//** 获取沙箱key start *//* - String sandboxKey = GetSignKey(); - *//** 获取沙箱key end *//* - String sign = SignatureUtil.createSign(weChatPayReqInfo, sandboxKey, "UTF-8"); // 测试 todo del - weChatPayReqInfo.setSign(sign); - String unifiedXmL = XmlUtil.toSplitXml(weChatPayReqInfo); - - String unifiedOrderResultXmL = HttpReqUtil.HttpsDefaultExecute("POST", wechatConfig.getUnified_order_url(), null, unifiedXmL, null); - log.error("支付信息:" + unifiedOrderResultXmL); - // 签名校验 - SortedMap sortedMap = null; - // 组装支付参数 - WechatCallBackInfo wechatCallBackInfo = XmlUtil.getObjectFromXML(unifiedOrderResultXmL, WechatCallBackInfo.class); - Long timeStamp = System.currentTimeMillis()/1000; - sortedMap = new TreeMap<>(); - sortedMap.put("appid",wechatConfig.getApp_id()); - sortedMap.put("partnerid",wechatConfig.getMch_id()); - sortedMap.put("prepayid",wechatCallBackInfo.getPrepay_id()); - sortedMap.put("noncestr",wechatCallBackInfo.getNonce_str()); - sortedMap.put("timestamp",timeStamp); - sortedMap.put("package","Sign=WXPay"); - String secondSign = SignatureUtil.createSign(sortedMap, wechatConfig.getApi_key(), "UTF-8"); - sortedMap.put("sign",secondSign); - - return sortedMap; - } catch (Exception e) { - log.error("AlipayTest -> createOrder:生成订单错误", e); - } - return null; - }*/ - - - /** - * @desc 获取沙箱key - */ - /*public String GetSignKey() throws Exception { - String nonce_str = WXPayUtil.generateNonceStr(); //生成随机字符 - Map param = new HashMap<>(); - param.put("mch_id", wechatConfig.getMch_id()); //需要真实商户号 - param.put("nonce_str", nonce_str); //随机字符 - String sign = WXPayUtil.generateSignature(param, wechatConfig.getApi_key(), WXPayConstants.SignType.MD5); //通过SDK生成签名其中API_KEY为商户对应的真实密钥 - param.put("sign", sign); - String xml = WXPayUtil.mapToXml(param); //将map转换为xml格式 - String url = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey"; //沙箱密钥获取api - String signKey = HttpUtil.post(url, xml); - System.out.println("signkey+"+signKey); - Map param1 = new HashMap(); - param1 = WXPayUtil.xmlToMap(signKey.toString()); - String key = param1.get("sandbox_signkey"); - return key; - }*/ - - - @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) - @ApiOperation(value = "微信分账") - @ResponseBody - public ResponseData wxProfitsharing() { - try { - Map param = new LinkedHashMap<>(); - param.put("appid", "wx637bd6f7314daa46"); - param.put("mch_id", "1289663601"); - param.put("sub_mch_id" , "1609882817"); - param.put("transaction_id" , "4200001152202106091959467542"); - param.put("out_order_no" , "HF2021060901121681200"); - param.put("nonce_str" , WxUtils.makeNonStr()); - - List> receiversList = new ArrayList<>(); - Map receiversMap = new LinkedHashMap<>(); - receiversMap.put("type", "MERCHANT_ID"); - receiversMap.put("account", "1603942866"); - receiversMap.put("amount", 1); - receiversMap.put("description", "分给1603942866商户"); - //receiversMap.put("name", "个体户黎杨珍"); - receiversList.add(receiversMap); - param.put("receivers" , JSONObject.toJSONString(receiversList)); - - String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); - param.put("sign" , signStr); - - /*String certPath = "/path/to/apiclient_cert.p12"; - - String post = getToken("POST", "/v3/pay/transactions/h5", JSONObject.toJSONString(param)); - - Map header = new HashMap<>(); - header.put("Accept","application/json"); - header.put("Authorization", "WECHATPAY2-SHA256-RSA2048 " + post);*/ - - //JSONObject object = HttpsUtils.doWxPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing", param, header); - - //String url = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing"; - String xm = WxUtils.mapToXml(param); - // String rest = String.valueOf(HttpsUtils.postData(url, xm)); - return ResponseMsgUtil.success(this.doRefundRequest(param.get("mch_id"),null, xm)); - // return ResponseMsgUtil.success(null); - - } catch (Exception e) { - log.error("CmsContentController --> getCorporateAdvertising() error!", e); - return ResponseMsgUtil.exception(e); - } - } - - //微信小程序读取双向证书 - private static CloseableHttpClient readCertificate(String mchId) throws Exception{ - /** - * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 - */ - KeyStore keyStore = KeyStore.getInstance("PKCS12"); - //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 - FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-cweb/src/main/resources/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(); - } - } - @RequestMapping(value = "/addLedgerReceiver", method = RequestMethod.POST) @ApiOperation(value = "微信支付 -> 添加分账接收方") public void addLedgerReceiver(HttpServletRequest request, HttpServletResponse response) { diff --git a/hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordMapper.java b/hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordMapper.java new file mode 100644 index 00000000..3d695b56 --- /dev/null +++ b/hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordMapper.java @@ -0,0 +1,110 @@ +package com.hai.dao; + +import com.hai.entity.HighProfitSharingRecord; +import com.hai.entity.HighProfitSharingRecordExample; +import java.util.List; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.DeleteProvider; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.InsertProvider; +import org.apache.ibatis.annotations.Options; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.annotations.UpdateProvider; +import org.apache.ibatis.type.JdbcType; +import org.springframework.stereotype.Repository; + +/** + * + * 代码由工具生成,请勿修改!!! + * 如果需要扩展请在其父类进行扩展 + * + **/ +@Repository +public interface HighProfitSharingRecordMapper extends HighProfitSharingRecordMapperExt { + @SelectProvider(type=HighProfitSharingRecordSqlProvider.class, method="countByExample") + long countByExample(HighProfitSharingRecordExample example); + + @DeleteProvider(type=HighProfitSharingRecordSqlProvider.class, method="deleteByExample") + int deleteByExample(HighProfitSharingRecordExample example); + + @Delete({ + "delete from high_profit_sharing_record", + "where id = #{id,jdbcType=BIGINT}" + }) + int deleteByPrimaryKey(Long id); + + @Insert({ + "insert into high_profit_sharing_record (transaction_id, out_order_no, ", + "order_id, price, ", + "content, create_time, ", + "`status`)", + "values (#{transactionId,jdbcType=VARCHAR}, #{outOrderNo,jdbcType=VARCHAR}, ", + "#{orderId,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, ", + "#{content,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ", + "#{status,jdbcType=VARCHAR})" + }) + @Options(useGeneratedKeys=true,keyProperty="id") + int insert(HighProfitSharingRecord record); + + @InsertProvider(type=HighProfitSharingRecordSqlProvider.class, method="insertSelective") + @Options(useGeneratedKeys=true,keyProperty="id") + int insertSelective(HighProfitSharingRecord record); + + @SelectProvider(type=HighProfitSharingRecordSqlProvider.class, method="selectByExample") + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="transaction_id", property="transactionId", jdbcType=JdbcType.VARCHAR), + @Result(column="out_order_no", property="outOrderNo", jdbcType=JdbcType.VARCHAR), + @Result(column="order_id", property="orderId", jdbcType=JdbcType.VARCHAR), + @Result(column="price", property="price", jdbcType=JdbcType.DECIMAL), + @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR), + @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="status", property="status", jdbcType=JdbcType.VARCHAR) + }) + List selectByExample(HighProfitSharingRecordExample example); + + @Select({ + "select", + "id, transaction_id, out_order_no, order_id, price, content, create_time, `status`", + "from high_profit_sharing_record", + "where id = #{id,jdbcType=BIGINT}" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="transaction_id", property="transactionId", jdbcType=JdbcType.VARCHAR), + @Result(column="out_order_no", property="outOrderNo", jdbcType=JdbcType.VARCHAR), + @Result(column="order_id", property="orderId", jdbcType=JdbcType.VARCHAR), + @Result(column="price", property="price", jdbcType=JdbcType.DECIMAL), + @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR), + @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="status", property="status", jdbcType=JdbcType.VARCHAR) + }) + HighProfitSharingRecord selectByPrimaryKey(Long id); + + @UpdateProvider(type=HighProfitSharingRecordSqlProvider.class, method="updateByExampleSelective") + int updateByExampleSelective(@Param("record") HighProfitSharingRecord record, @Param("example") HighProfitSharingRecordExample example); + + @UpdateProvider(type=HighProfitSharingRecordSqlProvider.class, method="updateByExample") + int updateByExample(@Param("record") HighProfitSharingRecord record, @Param("example") HighProfitSharingRecordExample example); + + @UpdateProvider(type=HighProfitSharingRecordSqlProvider.class, method="updateByPrimaryKeySelective") + int updateByPrimaryKeySelective(HighProfitSharingRecord record); + + @Update({ + "update high_profit_sharing_record", + "set transaction_id = #{transactionId,jdbcType=VARCHAR},", + "out_order_no = #{outOrderNo,jdbcType=VARCHAR},", + "order_id = #{orderId,jdbcType=VARCHAR},", + "price = #{price,jdbcType=DECIMAL},", + "content = #{content,jdbcType=VARCHAR},", + "create_time = #{createTime,jdbcType=TIMESTAMP},", + "`status` = #{status,jdbcType=VARCHAR}", + "where id = #{id,jdbcType=BIGINT}" + }) + int updateByPrimaryKey(HighProfitSharingRecord record); +} \ No newline at end of file diff --git a/hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordMapperExt.java new file mode 100644 index 00000000..ac6e5957 --- /dev/null +++ b/hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordMapperExt.java @@ -0,0 +1,7 @@ +package com.hai.dao; + +/** + * mapper扩展类 + */ +public interface HighProfitSharingRecordMapperExt { +} \ No newline at end of file diff --git a/hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordSqlProvider.java new file mode 100644 index 00000000..aec0bd55 --- /dev/null +++ b/hai-service/src/main/java/com/hai/dao/HighProfitSharingRecordSqlProvider.java @@ -0,0 +1,276 @@ +package com.hai.dao; + +import com.hai.entity.HighProfitSharingRecord; +import com.hai.entity.HighProfitSharingRecordExample.Criteria; +import com.hai.entity.HighProfitSharingRecordExample.Criterion; +import com.hai.entity.HighProfitSharingRecordExample; +import java.util.List; +import java.util.Map; +import org.apache.ibatis.jdbc.SQL; + +public class HighProfitSharingRecordSqlProvider { + + public String countByExample(HighProfitSharingRecordExample example) { + SQL sql = new SQL(); + sql.SELECT("count(*)").FROM("high_profit_sharing_record"); + applyWhere(sql, example, false); + return sql.toString(); + } + + public String deleteByExample(HighProfitSharingRecordExample example) { + SQL sql = new SQL(); + sql.DELETE_FROM("high_profit_sharing_record"); + applyWhere(sql, example, false); + return sql.toString(); + } + + public String insertSelective(HighProfitSharingRecord record) { + SQL sql = new SQL(); + sql.INSERT_INTO("high_profit_sharing_record"); + + if (record.getTransactionId() != null) { + sql.VALUES("transaction_id", "#{transactionId,jdbcType=VARCHAR}"); + } + + if (record.getOutOrderNo() != null) { + sql.VALUES("out_order_no", "#{outOrderNo,jdbcType=VARCHAR}"); + } + + if (record.getOrderId() != null) { + sql.VALUES("order_id", "#{orderId,jdbcType=VARCHAR}"); + } + + if (record.getPrice() != null) { + sql.VALUES("price", "#{price,jdbcType=DECIMAL}"); + } + + if (record.getContent() != null) { + sql.VALUES("content", "#{content,jdbcType=VARCHAR}"); + } + + if (record.getCreateTime() != null) { + sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}"); + } + + if (record.getStatus() != null) { + sql.VALUES("`status`", "#{status,jdbcType=VARCHAR}"); + } + + return sql.toString(); + } + + public String selectByExample(HighProfitSharingRecordExample example) { + SQL sql = new SQL(); + if (example != null && example.isDistinct()) { + sql.SELECT_DISTINCT("id"); + } else { + sql.SELECT("id"); + } + sql.SELECT("transaction_id"); + sql.SELECT("out_order_no"); + sql.SELECT("order_id"); + sql.SELECT("price"); + sql.SELECT("content"); + sql.SELECT("create_time"); + sql.SELECT("`status`"); + sql.FROM("high_profit_sharing_record"); + applyWhere(sql, example, false); + + if (example != null && example.getOrderByClause() != null) { + sql.ORDER_BY(example.getOrderByClause()); + } + + return sql.toString(); + } + + public String updateByExampleSelective(Map parameter) { + HighProfitSharingRecord record = (HighProfitSharingRecord) parameter.get("record"); + HighProfitSharingRecordExample example = (HighProfitSharingRecordExample) parameter.get("example"); + + SQL sql = new SQL(); + sql.UPDATE("high_profit_sharing_record"); + + if (record.getId() != null) { + sql.SET("id = #{record.id,jdbcType=BIGINT}"); + } + + if (record.getTransactionId() != null) { + sql.SET("transaction_id = #{record.transactionId,jdbcType=VARCHAR}"); + } + + if (record.getOutOrderNo() != null) { + sql.SET("out_order_no = #{record.outOrderNo,jdbcType=VARCHAR}"); + } + + if (record.getOrderId() != null) { + sql.SET("order_id = #{record.orderId,jdbcType=VARCHAR}"); + } + + if (record.getPrice() != null) { + sql.SET("price = #{record.price,jdbcType=DECIMAL}"); + } + + if (record.getContent() != null) { + sql.SET("content = #{record.content,jdbcType=VARCHAR}"); + } + + if (record.getCreateTime() != null) { + sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); + } + + if (record.getStatus() != null) { + sql.SET("`status` = #{record.status,jdbcType=VARCHAR}"); + } + + applyWhere(sql, example, true); + return sql.toString(); + } + + public String updateByExample(Map parameter) { + SQL sql = new SQL(); + sql.UPDATE("high_profit_sharing_record"); + + sql.SET("id = #{record.id,jdbcType=BIGINT}"); + sql.SET("transaction_id = #{record.transactionId,jdbcType=VARCHAR}"); + sql.SET("out_order_no = #{record.outOrderNo,jdbcType=VARCHAR}"); + sql.SET("order_id = #{record.orderId,jdbcType=VARCHAR}"); + sql.SET("price = #{record.price,jdbcType=DECIMAL}"); + sql.SET("content = #{record.content,jdbcType=VARCHAR}"); + sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); + sql.SET("`status` = #{record.status,jdbcType=VARCHAR}"); + + HighProfitSharingRecordExample example = (HighProfitSharingRecordExample) parameter.get("example"); + applyWhere(sql, example, true); + return sql.toString(); + } + + public String updateByPrimaryKeySelective(HighProfitSharingRecord record) { + SQL sql = new SQL(); + sql.UPDATE("high_profit_sharing_record"); + + if (record.getTransactionId() != null) { + sql.SET("transaction_id = #{transactionId,jdbcType=VARCHAR}"); + } + + if (record.getOutOrderNo() != null) { + sql.SET("out_order_no = #{outOrderNo,jdbcType=VARCHAR}"); + } + + if (record.getOrderId() != null) { + sql.SET("order_id = #{orderId,jdbcType=VARCHAR}"); + } + + if (record.getPrice() != null) { + sql.SET("price = #{price,jdbcType=DECIMAL}"); + } + + if (record.getContent() != null) { + sql.SET("content = #{content,jdbcType=VARCHAR}"); + } + + if (record.getCreateTime() != null) { + sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}"); + } + + if (record.getStatus() != null) { + sql.SET("`status` = #{status,jdbcType=VARCHAR}"); + } + + sql.WHERE("id = #{id,jdbcType=BIGINT}"); + + return sql.toString(); + } + + protected void applyWhere(SQL sql, HighProfitSharingRecordExample example, boolean includeExamplePhrase) { + if (example == null) { + return; + } + + String parmPhrase1; + String parmPhrase1_th; + String parmPhrase2; + String parmPhrase2_th; + String parmPhrase3; + String parmPhrase3_th; + if (includeExamplePhrase) { + parmPhrase1 = "%s #{example.oredCriteria[%d].allCriteria[%d].value}"; + parmPhrase1_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}"; + parmPhrase2 = "%s #{example.oredCriteria[%d].allCriteria[%d].value} and #{example.oredCriteria[%d].criteria[%d].secondValue}"; + parmPhrase2_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{example.oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}"; + parmPhrase3 = "#{example.oredCriteria[%d].allCriteria[%d].value[%d]}"; + parmPhrase3_th = "#{example.oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}"; + } else { + parmPhrase1 = "%s #{oredCriteria[%d].allCriteria[%d].value}"; + parmPhrase1_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}"; + parmPhrase2 = "%s #{oredCriteria[%d].allCriteria[%d].value} and #{oredCriteria[%d].criteria[%d].secondValue}"; + parmPhrase2_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}"; + parmPhrase3 = "#{oredCriteria[%d].allCriteria[%d].value[%d]}"; + parmPhrase3_th = "#{oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}"; + } + + StringBuilder sb = new StringBuilder(); + List oredCriteria = example.getOredCriteria(); + boolean firstCriteria = true; + for (int i = 0; i < oredCriteria.size(); i++) { + Criteria criteria = oredCriteria.get(i); + if (criteria.isValid()) { + if (firstCriteria) { + firstCriteria = false; + } else { + sb.append(" or "); + } + + sb.append('('); + List criterions = criteria.getAllCriteria(); + boolean firstCriterion = true; + for (int j = 0; j < criterions.size(); j++) { + Criterion criterion = criterions.get(j); + if (firstCriterion) { + firstCriterion = false; + } else { + sb.append(" and "); + } + + if (criterion.isNoValue()) { + sb.append(criterion.getCondition()); + } else if (criterion.isSingleValue()) { + if (criterion.getTypeHandler() == null) { + sb.append(String.format(parmPhrase1, criterion.getCondition(), i, j)); + } else { + sb.append(String.format(parmPhrase1_th, criterion.getCondition(), i, j,criterion.getTypeHandler())); + } + } else if (criterion.isBetweenValue()) { + if (criterion.getTypeHandler() == null) { + sb.append(String.format(parmPhrase2, criterion.getCondition(), i, j, i, j)); + } else { + sb.append(String.format(parmPhrase2_th, criterion.getCondition(), i, j, criterion.getTypeHandler(), i, j, criterion.getTypeHandler())); + } + } else if (criterion.isListValue()) { + sb.append(criterion.getCondition()); + sb.append(" ("); + List listItems = (List) criterion.getValue(); + boolean comma = false; + for (int k = 0; k < listItems.size(); k++) { + if (comma) { + sb.append(", "); + } else { + comma = true; + } + if (criterion.getTypeHandler() == null) { + sb.append(String.format(parmPhrase3, i, j, k)); + } else { + sb.append(String.format(parmPhrase3_th, i, j, k, criterion.getTypeHandler())); + } + } + sb.append(')'); + } + } + sb.append(')'); + } + } + + if (sb.length() > 0) { + sql.WHERE(sb.toString()); + } + } +} \ No newline at end of file diff --git a/hai-service/src/main/java/com/hai/entity/HighProfitSharingRecord.java b/hai-service/src/main/java/com/hai/entity/HighProfitSharingRecord.java new file mode 100644 index 00000000..31aa948f --- /dev/null +++ b/hai-service/src/main/java/com/hai/entity/HighProfitSharingRecord.java @@ -0,0 +1,178 @@ +package com.hai.entity; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * high_profit_sharing_record + * @author + */ +/** + * + * 代码由工具生成 + * + **/ +public class HighProfitSharingRecord implements Serializable { + /** + * 主键ID + */ + private Long id; + + /** + * 微信订单号 + */ + private String transactionId; + + /** + * 商户分账单号 + */ + private String outOrderNo; + + /** + * 微信分账单号 + */ + private String orderId; + + /** + * 分账金额 + */ + private BigDecimal price; + + /** + * 报文内容 + */ + private String content; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 状态(以微信返回为准) + */ + private String status; + + private static final long serialVersionUID = 1L; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } + + public String getOutOrderNo() { + return outOrderNo; + } + + public void setOutOrderNo(String outOrderNo) { + this.outOrderNo = outOrderNo; + } + + public String getOrderId() { + return orderId; + } + + public void setOrderId(String orderId) { + this.orderId = orderId; + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + HighProfitSharingRecord other = (HighProfitSharingRecord) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getTransactionId() == null ? other.getTransactionId() == null : this.getTransactionId().equals(other.getTransactionId())) + && (this.getOutOrderNo() == null ? other.getOutOrderNo() == null : this.getOutOrderNo().equals(other.getOutOrderNo())) + && (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId())) + && (this.getPrice() == null ? other.getPrice() == null : this.getPrice().equals(other.getPrice())) + && (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) + && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getTransactionId() == null) ? 0 : getTransactionId().hashCode()); + result = prime * result + ((getOutOrderNo() == null) ? 0 : getOutOrderNo().hashCode()); + result = prime * result + ((getOrderId() == null) ? 0 : getOrderId().hashCode()); + result = prime * result + ((getPrice() == null) ? 0 : getPrice().hashCode()); + result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", transactionId=").append(transactionId); + sb.append(", outOrderNo=").append(outOrderNo); + sb.append(", orderId=").append(orderId); + sb.append(", price=").append(price); + sb.append(", content=").append(content); + sb.append(", createTime=").append(createTime); + sb.append(", status=").append(status); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/hai-service/src/main/java/com/hai/entity/HighProfitSharingRecordExample.java b/hai-service/src/main/java/com/hai/entity/HighProfitSharingRecordExample.java new file mode 100644 index 00000000..94b1d4e0 --- /dev/null +++ b/hai-service/src/main/java/com/hai/entity/HighProfitSharingRecordExample.java @@ -0,0 +1,754 @@ +package com.hai.entity; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class HighProfitSharingRecordExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + private Integer limit; + + private Long offset; + + public HighProfitSharingRecordExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + + public Integer getLimit() { + return limit; + } + + public void setOffset(Long offset) { + this.offset = offset; + } + + public Long getOffset() { + return offset; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andTransactionIdIsNull() { + addCriterion("transaction_id is null"); + return (Criteria) this; + } + + public Criteria andTransactionIdIsNotNull() { + addCriterion("transaction_id is not null"); + return (Criteria) this; + } + + public Criteria andTransactionIdEqualTo(String value) { + addCriterion("transaction_id =", value, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdNotEqualTo(String value) { + addCriterion("transaction_id <>", value, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdGreaterThan(String value) { + addCriterion("transaction_id >", value, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdGreaterThanOrEqualTo(String value) { + addCriterion("transaction_id >=", value, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdLessThan(String value) { + addCriterion("transaction_id <", value, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdLessThanOrEqualTo(String value) { + addCriterion("transaction_id <=", value, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdLike(String value) { + addCriterion("transaction_id like", value, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdNotLike(String value) { + addCriterion("transaction_id not like", value, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdIn(List values) { + addCriterion("transaction_id in", values, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdNotIn(List values) { + addCriterion("transaction_id not in", values, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdBetween(String value1, String value2) { + addCriterion("transaction_id between", value1, value2, "transactionId"); + return (Criteria) this; + } + + public Criteria andTransactionIdNotBetween(String value1, String value2) { + addCriterion("transaction_id not between", value1, value2, "transactionId"); + return (Criteria) this; + } + + public Criteria andOutOrderNoIsNull() { + addCriterion("out_order_no is null"); + return (Criteria) this; + } + + public Criteria andOutOrderNoIsNotNull() { + addCriterion("out_order_no is not null"); + return (Criteria) this; + } + + public Criteria andOutOrderNoEqualTo(String value) { + addCriterion("out_order_no =", value, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoNotEqualTo(String value) { + addCriterion("out_order_no <>", value, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoGreaterThan(String value) { + addCriterion("out_order_no >", value, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoGreaterThanOrEqualTo(String value) { + addCriterion("out_order_no >=", value, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoLessThan(String value) { + addCriterion("out_order_no <", value, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoLessThanOrEqualTo(String value) { + addCriterion("out_order_no <=", value, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoLike(String value) { + addCriterion("out_order_no like", value, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoNotLike(String value) { + addCriterion("out_order_no not like", value, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoIn(List values) { + addCriterion("out_order_no in", values, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoNotIn(List values) { + addCriterion("out_order_no not in", values, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoBetween(String value1, String value2) { + addCriterion("out_order_no between", value1, value2, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOutOrderNoNotBetween(String value1, String value2) { + addCriterion("out_order_no not between", value1, value2, "outOrderNo"); + return (Criteria) this; + } + + public Criteria andOrderIdIsNull() { + addCriterion("order_id is null"); + return (Criteria) this; + } + + public Criteria andOrderIdIsNotNull() { + addCriterion("order_id is not null"); + return (Criteria) this; + } + + public Criteria andOrderIdEqualTo(String value) { + addCriterion("order_id =", value, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdNotEqualTo(String value) { + addCriterion("order_id <>", value, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdGreaterThan(String value) { + addCriterion("order_id >", value, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdGreaterThanOrEqualTo(String value) { + addCriterion("order_id >=", value, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdLessThan(String value) { + addCriterion("order_id <", value, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdLessThanOrEqualTo(String value) { + addCriterion("order_id <=", value, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdLike(String value) { + addCriterion("order_id like", value, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdNotLike(String value) { + addCriterion("order_id not like", value, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdIn(List values) { + addCriterion("order_id in", values, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdNotIn(List values) { + addCriterion("order_id not in", values, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdBetween(String value1, String value2) { + addCriterion("order_id between", value1, value2, "orderId"); + return (Criteria) this; + } + + public Criteria andOrderIdNotBetween(String value1, String value2) { + addCriterion("order_id not between", value1, value2, "orderId"); + return (Criteria) this; + } + + public Criteria andPriceIsNull() { + addCriterion("price is null"); + return (Criteria) this; + } + + public Criteria andPriceIsNotNull() { + addCriterion("price is not null"); + return (Criteria) this; + } + + public Criteria andPriceEqualTo(BigDecimal value) { + addCriterion("price =", value, "price"); + return (Criteria) this; + } + + public Criteria andPriceNotEqualTo(BigDecimal value) { + addCriterion("price <>", value, "price"); + return (Criteria) this; + } + + public Criteria andPriceGreaterThan(BigDecimal value) { + addCriterion("price >", value, "price"); + return (Criteria) this; + } + + public Criteria andPriceGreaterThanOrEqualTo(BigDecimal value) { + addCriterion("price >=", value, "price"); + return (Criteria) this; + } + + public Criteria andPriceLessThan(BigDecimal value) { + addCriterion("price <", value, "price"); + return (Criteria) this; + } + + public Criteria andPriceLessThanOrEqualTo(BigDecimal value) { + addCriterion("price <=", value, "price"); + return (Criteria) this; + } + + public Criteria andPriceIn(List values) { + addCriterion("price in", values, "price"); + return (Criteria) this; + } + + public Criteria andPriceNotIn(List values) { + addCriterion("price not in", values, "price"); + return (Criteria) this; + } + + public Criteria andPriceBetween(BigDecimal value1, BigDecimal value2) { + addCriterion("price between", value1, value2, "price"); + return (Criteria) this; + } + + public Criteria andPriceNotBetween(BigDecimal value1, BigDecimal value2) { + addCriterion("price not between", value1, value2, "price"); + return (Criteria) this; + } + + public Criteria andContentIsNull() { + addCriterion("content is null"); + return (Criteria) this; + } + + public Criteria andContentIsNotNull() { + addCriterion("content is not null"); + return (Criteria) this; + } + + public Criteria andContentEqualTo(String value) { + addCriterion("content =", value, "content"); + return (Criteria) this; + } + + public Criteria andContentNotEqualTo(String value) { + addCriterion("content <>", value, "content"); + return (Criteria) this; + } + + public Criteria andContentGreaterThan(String value) { + addCriterion("content >", value, "content"); + return (Criteria) this; + } + + public Criteria andContentGreaterThanOrEqualTo(String value) { + addCriterion("content >=", value, "content"); + return (Criteria) this; + } + + public Criteria andContentLessThan(String value) { + addCriterion("content <", value, "content"); + return (Criteria) this; + } + + public Criteria andContentLessThanOrEqualTo(String value) { + addCriterion("content <=", value, "content"); + return (Criteria) this; + } + + public Criteria andContentLike(String value) { + addCriterion("content like", value, "content"); + return (Criteria) this; + } + + public Criteria andContentNotLike(String value) { + addCriterion("content not like", value, "content"); + return (Criteria) this; + } + + public Criteria andContentIn(List values) { + addCriterion("content in", values, "content"); + return (Criteria) this; + } + + public Criteria andContentNotIn(List values) { + addCriterion("content not in", values, "content"); + return (Criteria) this; + } + + public Criteria andContentBetween(String value1, String value2) { + addCriterion("content between", value1, value2, "content"); + return (Criteria) this; + } + + public Criteria andContentNotBetween(String value1, String value2) { + addCriterion("content not between", value1, value2, "content"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Date value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Date value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Date value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Date value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Date value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Date value1, Date value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Date value1, Date value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andStatusIsNull() { + addCriterion("`status` is null"); + return (Criteria) this; + } + + public Criteria andStatusIsNotNull() { + addCriterion("`status` is not null"); + return (Criteria) this; + } + + public Criteria andStatusEqualTo(String value) { + addCriterion("`status` =", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotEqualTo(String value) { + addCriterion("`status` <>", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThan(String value) { + addCriterion("`status` >", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThanOrEqualTo(String value) { + addCriterion("`status` >=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThan(String value) { + addCriterion("`status` <", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThanOrEqualTo(String value) { + addCriterion("`status` <=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLike(String value) { + addCriterion("`status` like", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotLike(String value) { + addCriterion("`status` not like", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusIn(List values) { + addCriterion("`status` in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotIn(List values) { + addCriterion("`status` not in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusBetween(String value1, String value2) { + addCriterion("`status` between", value1, value2, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotBetween(String value1, String value2) { + addCriterion("`status` not between", value1, value2, "status"); + return (Criteria) this; + } + } + + /** + */ + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/hai-service/src/main/java/com/hai/model/ResultProfitSharing.java b/hai-service/src/main/java/com/hai/model/ResultProfitSharing.java new file mode 100644 index 00000000..32054a08 --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/ResultProfitSharing.java @@ -0,0 +1,98 @@ +package com.hai.model; + +/** + * 分账结果 + */ +public class ResultProfitSharing { + + private String return_code; + private String result_code; + private String mch_id; + private String sub_mch_id; + private String appid; + private String nonce_str; + private String sign; + private String transaction_id; + private String out_order_no; + private String order_id; + + public String getReturn_code() { + return return_code; + } + + public void setReturn_code(String return_code) { + this.return_code = return_code; + } + + public String getResult_code() { + return result_code; + } + + public void setResult_code(String result_code) { + this.result_code = result_code; + } + + public String getMch_id() { + return mch_id; + } + + public void setMch_id(String mch_id) { + this.mch_id = mch_id; + } + + public String getSub_mch_id() { + return sub_mch_id; + } + + public void setSub_mch_id(String sub_mch_id) { + this.sub_mch_id = sub_mch_id; + } + + public String getAppid() { + return appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getNonce_str() { + return nonce_str; + } + + public void setNonce_str(String nonce_str) { + this.nonce_str = nonce_str; + } + + public String getSign() { + return sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public String getTransaction_id() { + return transaction_id; + } + + public void setTransaction_id(String transaction_id) { + this.transaction_id = transaction_id; + } + + public String getOut_order_no() { + return out_order_no; + } + + public void setOut_order_no(String out_order_no) { + this.out_order_no = out_order_no; + } + + public String getOrder_id() { + return order_id; + } + + public void setOrder_id(String order_id) { + this.order_id = order_id; + } +} diff --git a/hai-service/src/main/java/com/hai/service/HighProfitSharingRecordService.java b/hai-service/src/main/java/com/hai/service/HighProfitSharingRecordService.java new file mode 100644 index 00000000..5431c9a0 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighProfitSharingRecordService.java @@ -0,0 +1,12 @@ +package com.hai.service; + +import com.hai.entity.HighProfitSharingRecord; + +/** + * 分账记录 + */ +public interface HighProfitSharingRecordService { + + + void insert(HighProfitSharingRecord highProfitSharingRecord); +} diff --git a/hai-service/src/main/java/com/hai/service/impl/HighProfitSharingRecordServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighProfitSharingRecordServiceImpl.java new file mode 100644 index 00000000..98dba1c6 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/HighProfitSharingRecordServiceImpl.java @@ -0,0 +1,20 @@ +package com.hai.service.impl; + +import com.hai.dao.HighProfitSharingRecordMapper; +import com.hai.entity.HighProfitSharingRecord; +import com.hai.service.HighProfitSharingRecordService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service("highProfitSharingRecord") +public class HighProfitSharingRecordServiceImpl implements HighProfitSharingRecordService { + + @Resource + private HighProfitSharingRecordMapper highProfitSharingRecordMapper; + + @Override + public void insert(HighProfitSharingRecord highProfitSharingRecord) { + highProfitSharingRecordMapper.insert(highProfitSharingRecord); + } +} 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 2efd8792..b342cc4d 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 @@ -1,21 +1,38 @@ package com.hai.service.pay.impl; +import com.alibaba.fastjson.JSONObject; 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.WxUtils; import com.hai.dao.HighUserCouponMapper; import com.hai.entity.*; +import com.hai.model.ResultProfitSharing; import com.hai.service.*; import com.hai.service.pay.PayService; +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.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import javax.net.ssl.SSLContext; +import java.io.FileInputStream; import java.math.BigDecimal; -import java.util.Calendar; -import java.util.Date; -import java.util.Map; +import java.security.KeyStore; +import java.util.*; /** * @Auther: 胡锐 @@ -25,6 +42,8 @@ import java.util.Map; @Service("goodsOrderService") public class GoodsOrderServiceImpl implements PayService { + private static Logger log = LoggerFactory.getLogger(GoodsOrderServiceImpl.class); + @Resource private HighOrderService highOrderService; @@ -40,6 +59,9 @@ public class GoodsOrderServiceImpl implements PayService { @Resource private HighUserCouponMapper highUserCouponMapper; + @Resource + private HighProfitSharingRecordService highProfitSharingRecordService; + @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void paySuccess(Map map, String payType) throws Exception { @@ -53,59 +75,164 @@ public class GoodsOrderServiceImpl implements PayService { if (order == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); } - order.setPaySerialNo(map.get("transaction_id")); // 支付流水号 - order.setPayRealPrice(new BigDecimal(map.get("total_fee")).divide(new BigDecimal("100"))); // 实付金额 - order.setPayTime(new Date()); // 支付时间 - order.setPayModel(2); // 支付模式:1 金币,2 第三方平台,3 混合 - order.setPayType(2); // 支付方式: 1:支付宝 2:微信 3:金币 - order.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 - - for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { - // 商品类型 商品类型 1:卡卷 2:金币充值 - if (highChildOrder.getGoodsType() == 1) { - highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 - HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); - code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 - code.setReceiveTime(new Date()); - highCouponCodeService.updateCouponCode(code); - - HighCoupon coupon = highCouponService.getCouponById(highChildOrder.getGoodsId()); - - // 卡卷关联用户 - HighUserCoupon highUserCoupon = new HighUserCoupon(); - highUserCoupon.setMerchantId(code.getMerchantId()); - highUserCoupon.setCouponId(code.getCouponId()); - highUserCoupon.setUserId(order.getMemId()); - highUserCoupon.setCouponCodeId(code.getId()); - highUserCoupon.setCreateTime(new Date()); - highUserCoupon.setQrCodeImg(code.getExt1()); - - // 计算使用有效期 - Calendar userEndTime = Calendar.getInstance(); - userEndTime.setTime(new Date()); - userEndTime.set(Calendar.HOUR_OF_DAY, 23); - userEndTime.set(Calendar.MINUTE, 59); - userEndTime.set(Calendar.SECOND, 59); - userEndTime.add(Calendar.DATE, coupon.getRecycleDay()); - if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) { - highUserCoupon.setUseEndTime(code.getUseEndTime()); - } else { - highUserCoupon.setUseEndTime(userEndTime.getTime()); + if (order.getOrderStatus() == 1) { + order.setPaySerialNo(map.get("transaction_id")); // 支付流水号 + order.setPayRealPrice(new BigDecimal(map.get("total_fee")).divide(new BigDecimal("100"))); // 实付金额 + order.setPayTime(new Date()); // 支付时间 + order.setPayModel(2); // 支付模式:1 金币,2 第三方平台,3 混合 + order.setPayType(2); // 支付方式: 1:支付宝 2:微信 3:金币 + order.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + + for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { + // 商品类型 商品类型 1:卡卷 2:金币充值 + if (highChildOrder.getGoodsType() == 1) { + highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); + code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 + code.setReceiveTime(new Date()); + highCouponCodeService.updateCouponCode(code); + + HighCoupon coupon = highCouponService.getCouponById(highChildOrder.getGoodsId()); + + // 卡卷关联用户 + HighUserCoupon highUserCoupon = new HighUserCoupon(); + highUserCoupon.setMerchantId(code.getMerchantId()); + highUserCoupon.setCouponId(code.getCouponId()); + highUserCoupon.setUserId(order.getMemId()); + highUserCoupon.setCouponCodeId(code.getId()); + highUserCoupon.setCreateTime(new Date()); + highUserCoupon.setQrCodeImg(code.getExt1()); + + // 计算使用有效期 + Calendar userEndTime = Calendar.getInstance(); + userEndTime.setTime(new Date()); + userEndTime.set(Calendar.HOUR_OF_DAY, 23); + userEndTime.set(Calendar.MINUTE, 59); + userEndTime.set(Calendar.SECOND, 59); + userEndTime.add(Calendar.DATE, coupon.getRecycleDay()); + if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) { + highUserCoupon.setUseEndTime(code.getUseEndTime()); + } else { + highUserCoupon.setUseEndTime(userEndTime.getTime()); + } + highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 + highUserCouponMapper.insert(highUserCoupon); } - highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 - highUserCouponMapper.insert(highUserCoupon); - } - if (highChildOrder.getGoodsType() == 2) { - highChildOrder.setChildOrdeStatus(3); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 - // 金币 1:100 - Integer goldNum = new BigDecimal(highChildOrder.getTotalPrice().toString()).multiply(new BigDecimal("100")).intValue(); - highUserService.goldHandle(highChildOrder.getGoodsId(), goldNum, 1, 1, highChildOrder.getId()); + if (highChildOrder.getGoodsType() == 2) { + highChildOrder.setChildOrdeStatus(3); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + // 金币 1:100 + Integer goldNum = new BigDecimal(highChildOrder.getTotalPrice().toString()).multiply(new BigDecimal("100")).intValue(); + highUserService.goldHandle(highChildOrder.getGoodsId(), goldNum, 1, 1, highChildOrder.getId()); + } } + + highOrderService.updateOrder(order); + + new Thread(() -> { + try { + Thread.sleep(60*1000); + BigDecimal rake = new BigDecimal("0.01"); + BigDecimal profitSharingAmount = order.getPayRealPrice().multiply(rake); + this.wxProfitsharing(order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }).start(); } + } + } + + + 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", "分给商户1603942866"); + 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); + + 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); + } + } - highOrderService.updateOrder(order); + //微信小程序读取双向证书 + private static 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"); + 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(); } } }