| | |
| | | package com.dsh.account.util; |
| | | |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.AlipayClient; |
| | | import com.alipay.api.CertAlipayRequest; |
| | | import com.alipay.api.DefaultAlipayClient; |
| | | import com.alipay.api.domain.AlipayTradeAppPayModel; |
| | | import com.alipay.api.domain.AlipayTradeQueryModel; |
| | | import com.alipay.api.domain.*; |
| | | import com.alipay.api.request.*; |
| | | import com.alipay.api.response.*; |
| | | import com.dsh.account.dto.Receivers; |
| | | import com.dsh.account.entity.OperatorUser; |
| | | import com.dsh.account.feignclient.competition.DeductionCompetitionsClient; |
| | | import com.dsh.account.feignclient.competition.model.PaymentCompetition; |
| | | import com.dsh.account.feignclient.course.CoursePackageClient; |
| | | import com.dsh.account.feignclient.course.model.TCoursePackagePayment; |
| | | import com.dsh.account.feignclient.other.SiteClient; |
| | | import com.dsh.account.feignclient.other.model.SiteBooking; |
| | | import com.dsh.account.mapper.RechargeRecordsMapper; |
| | | import com.dsh.account.util.httpClinet.HttpClientUtil; |
| | | //import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingReceiver; |
| | | //import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingRequest; |
| | | //import com.github.binarywang.wxpay.service.ProfitSharingV3Service; |
| | | //import com.github.binarywang.wxpay.service.WxPayService; |
| | | |
| | | import org.apache.commons.collections.map.HashedMap; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.bouncycastle.jce.provider.BouncyCastleProvider; |
| | | import org.dom4j.Document; |
| | | import org.dom4j.DocumentException; |
| | | import org.dom4j.Element; |
| | | import org.dom4j.io.SAXReader; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.crypto.BadPaddingException; |
| | | import javax.crypto.Cipher; |
| | | import javax.crypto.IllegalBlockSizeException; |
| | |
| | | */ |
| | | @Component |
| | | public class PayMoneyUtil { |
| | | private String aliAppid = "2021004103650328";//支付宝appid |
| | | private String aliAppid = "2021004105665036";//支付宝appid |
| | | |
| | | private String appPrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCUMAeeFUrZrc98qsBYCwC7ptFnPBqU5IIDMWMznjjNLaXd393vxvbl4xNZLOknKPYUdG/Xm2DgmqAvHawnfsyrm387V60M2XEA4PMTo0kZDWXhYPM7JhtISG0sTYRdclwew36lwkqQ3RnAc12+Ntx7Q19+kITq2vOX8vnBG0HhkFiiPVIeavXnrQ30robnTQSJU+FE9Umwm84k9fsLXtD38rsCVP3Seo2ubAiwDxC8TEHww7cpMIun+ikJJSSxFABkdRMFb6rx40zvjQoGIRtCpfftnMikJhaRurdjeJkqDwBBzDfAM0wB0v5V7K41VNvoVKcgfvxWEAuzC9w0VYdVAgMBAAECggEBAIGGNbJMRB9eF8SM7xBFlb9vgQrt8wH/dVBbI61jd5yHcLotSayiSP4I68l/Qs9ysxyP5Y4cBqJrJOXp1qay4yx//saczOo1SNuOw4h/qY3XMxy7A/7IQQJ+I8acfry7D5/oGlPCLjDOwQqBDAgNpcuryNU0dqlc9Zvzya+rJnuDspl2FvCbXkQBiihQCG+oQXvAWivRQquW1MmpqhSohevpABJPW4SSSIJhHyoC8GEIcDcOhZ9rLX1e8qndhS7xEBi3sGTunyaiv4zJtA5jHzQ8pH737+OhqdcMsr03cWfiKIlLGCC28ZX3X/fqqfByws5lvxViq4UIAP/et7VVkkECgYEA/I+MHPo1UgGBr1rDA9aP1ESpaDb3tC6HzVgvHid/Lle+zSvQiZ5q0BvqQogj3GU+FIfVtStC4wjINTKyyeoOWV7YTKcToUJPPCF98VCZsevY3tp2Z1rxqU90yjccNSPtwjwH9RQ8D96eU+4HByrh5qwFU3p2aNOIbv4B8z57xOUCgYEAljSghLWnLmSZcz+2KEBcy5Jg92lZZfQoNd88hBR2dnccQbK2yPanPrzsmqB76017x4t7JV1X3ssI0b1f42hF2r9gwC5AD6/GhTCRoiZIMuCz+EBexWBiG3IJLN7yh6CYYEVvKd+3iCkneSxxT4Xqo0AWlMnoV2lcu0fLV0KvgbECgYBLfYiu3Kb1ZRfjVyi1S/vfwco1KUDu7X2QBkzHIZ0lN/sDDpadm+lnXQCvdEvrw6NDtbpOFak/fU+Cfy3rpnc1hWD3wHTgnZZbbdNcPvBBuzIuonQDvq4/Ik3RZ5mZ1Kxrg1AJlEvDnpIKmjoljU7KiR5qbk9YU+oS6v+gOkv6dQKBgGAxtfcnqriQXqGrVMo0ZflNdmIcis87bSELJWNlA3Tc1TDR9jN/mx4XueNREetgxPvHPQdx3xtkpfJEuIsXtVzhIWISfJ5PMPENaMcSgzxqIXfEKa14C3yOLIgbA/GODOfir81+Y7iEuq3ko3CNT/Zazdtd7zlD1cpusS/iGioRAoGAE268pgJfIJkUY5qkQHClzv/OBUlhDzGUowfYPwhZ2TNISfm0zpWq1to4nIHVHDPTsVs5wEgGPO3fYzd284/lU180/NIqHa9cwHI9zNO3E8X8mP8H1WUaxon64fV6UQGXzMvd4l7v1GYzEMkNVqwPmpAwrlLzQOLpDe/dGY5lvJw=";//支付宝开发者应用私钥 |
| | | private String appPrivateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCi5i9nW/hGLJ3A06cZxTQdviFC7THpdSihoTYGLr9q006hu0V26ecBMY/o4w5bvIX0Ok/yofmZsVcCJpAPvbXL/uqVrIjnRRxXiaeBFThlxoBUTdunvbUSDYfzlEhJr5NvUKI6H6lz2niXlQGx4qy8Hau4ccWit9kM8jwUvsBVQoFgJA+xrjMvooA7YLopQtpOD+UJr5thApTSf1xrnr1W12yolTLEH15JmNV372cqXrYUuqnY0QsaPtxeqJUGAOcGdVLllQ7easEznP8DFBvDdHATcmp2SHNQ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Z/6iaGdhbbu9unlsWj3uQKBgQCmZYdsbbZkd3ev6f8rwyvMz+DrCQyYpY44cegBYuJgrZiQnL2fJioeN7ixX0UM48SfwsZEIrzshP/LGAwnc2MdjxKUl4jLN8SEe0NAjXOnz9Zaw740+aOmLpXcLWdP4uM2gIhWsvW1tEkQZCXmm7c9s/RsU8Pmzv+YL3+fSijOzA==";//支付宝开发者应用私钥 |
| | | |
| | | private String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlDAHnhVK2a3PfKrAWAsAu6bRZzwalOSCAzFjM544zS2l3d/d78b25eMTWSzpJyj2FHRv15tg4JqgLx2sJ37Mq5t/O1etDNlxAODzE6NJGQ1l4WDzOyYbSEhtLE2EXXJcHsN+pcJKkN0ZwHNdvjbce0NffpCE6trzl/L5wRtB4ZBYoj1SHmr1560N9K6G500EiVPhRPVJsJvOJPX7C17Q9/K7AlT90nqNrmwIsA8QvExB8MO3KTCLp/opCSUksRQAZHUTBW+q8eNM740KBiEbQqX37ZzIpCYWkbq3Y3iZKg8AQcw3wDNMAdL+VeyuNVTb6FSnIH78VhALswvcNFWHVQIDAQAB";//支付宝应用公钥 |
| | | private String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAouYvZ1v4RiydwNOnGcU0Hb4hQu0x6XUooaE2Bi6/atNOobtFdunnATGP6OMOW7yF9DpP8qH5mbFXAiaQD721y/7qlayI50UcV4mngRU4ZcaAVE3bp721Eg2H85RISa+Tb1CiOh+pc9p4l5UBseKsvB2ruHHForfZDPI8FL7AVUKBYCQPsa4zL6KAO2C6KULaTg/lCa+bYQKU0n9ca569VtdsqJUyxB9eSZjVd+9nKl62FLqp2NELGj7cXqiVBgDnBnVS5ZUO3mrBM5z/AxQbw3RwE3JqdkhzUA1BFjejAlT2zIGNOjUFagF8ao0wGElYfuk0bum6Hz5qWAt02QdNNwIDAQAB";//支付宝应用公钥 |
| | | |
| | | private String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmu8n/4yTHWbn7VOrNc9OsLtDL1bEQ8gC1dHkj8Wy5z0mkaOsjJRIG/28ze12M0V8jdCKuuDr5Z1OPKiqf+XO3ypguEh+mYUVMBM/cZodDFQfTY1TKLWjvQCuaqlA+QUTCK6f7T7stsgyQ1o9Jj0rXZDz6PM4QHSTzjrLIBaeqM5WIBvH+fy/X+QG5Utd+/UT0kc0JyvuKhZ65yVUd/C9VcwJJAPliRsAQNrqYterwAJ9zvw9tF11wj9W0XgJ8Ccu4x3gR1vrlLRJJo/OA97RmxPQ+5hSacWQZCUd1dwiBq+YCrKVHGTj14izRHXrLc0yBlRXo7tBOIqcy3IsvKVthQIDAQAB";//支付宝支付公钥 |
| | | |
| | |
| | | model.setTotalAmount(amount);//付款金额 |
| | | model.setProductCode("QUICK_MSECURITY_PAY"); |
| | | model.setPassbackParams(passbackParams);//自定义参数 |
| | | |
| | | |
| | | //分账 |
| | | // Integer coursePackagePayments = coursePackageClient.queryByCode(outTradeNo); |
| | | // Integer paymentCompetitions = competitionsClient.queryByCode(outTradeNo); |
| | | // Integer siteBookings = siteClient.queryByCode(outTradeNo); |
| | | // List<Integer> stores = new ArrayList<>(); |
| | | // stores.add(coursePackagePayments); |
| | | // stores.add(paymentCompetitions); |
| | | // stores.add(siteBookings); |
| | | // |
| | | // OperatorUser operatorUser = siteClient.queryOperator(stores); |
| | | // |
| | | // String alipayProportion = operatorUser.getAlipayProportion(); |
| | | // String alipayNum = operatorUser.getAlipayNum(); |
| | | // |
| | | // ExtendParams extendParams = new ExtendParams(); |
| | | //// extendParams.setSysServiceProviderId("YOUR_SERVICE_PROVIDER_ID"); |
| | | // model.setExtendParams(extendParams); |
| | | // |
| | | // RoyaltyInfo royaltyInfo = new RoyaltyInfo(); |
| | | //// royaltyInfo.setRoyaltyType("transfer"); |
| | | // |
| | | // |
| | | // RoyaltyDetailInfos royaltyDetailInfo1 = new RoyaltyDetailInfos(); |
| | | // royaltyDetailInfo1.setTransOutType("userId"); |
| | | // royaltyDetailInfo1.setTransOut(aliAppid); |
| | | // royaltyDetailInfo1.setTransInType("loginName"); |
| | | // royaltyDetailInfo1.setTransIn("18398968484"); |
| | | // |
| | | // royaltyDetailInfo1.setDesc("分账描述1"); |
| | | // royaltyDetailInfo1.setAmountPercentage(alipayProportion); |
| | | // List<RoyaltyDetailInfos> royaltyDetailInfos = new ArrayList<>(); |
| | | // |
| | | // |
| | | // |
| | | // royaltyInfo.setRoyaltyDetailInfos(royaltyDetailInfos); |
| | | // model.setRoyaltyInfo(royaltyInfo); |
| | | // System.err.println("=================="+royaltyInfo); |
| | | // |
| | | request.setBizModel(model); |
| | | request.setNotifyUrl(callbackPath + notifyUrl); |
| | | try { |
| | |
| | | if("SUCCESS".equals(result_code)){ |
| | | String type = map1.get("trade_type"); |
| | | String prepay_id = map1.get("prepay_id"); |
| | | |
| | | |
| | | |
| | | |
| | | switch (type){ |
| | | case "JSAPI": |
| | | //重新进行签名后返回给前端 |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private RechargeRecordsMapper rereMapper; |
| | | |
| | | |
| | | /** |
| | |
| | | map1.put("transaction_id", map.get("transaction_id"));//微信支付订单号 |
| | | String result = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"; |
| | | map1.put("result", result); |
| | | |
| | | |
| | | |
| | | return map1; |
| | | }else{ |
| | | System.err.println(map.get("err_code_des")); |
| | |
| | | e.printStackTrace(); |
| | | } catch (DocumentException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Resource |
| | | private CoursePackageClient coursePackageClient; |
| | | @Resource |
| | | private DeductionCompetitionsClient competitionsClient; |
| | | |
| | | @Resource |
| | | private SiteClient siteClient; |
| | | // @Autowired |
| | | // private WxPayService wxPayService; |
| | | //分账 |
| | | // public ResultUtil order(String code) throws Exception { |
| | | // |
| | | // |
| | | // |
| | | // Integer coursePackagePayments = coursePackageClient.queryByCode(code); |
| | | // Integer paymentCompetitions = competitionsClient.queryByCode(code); |
| | | // Integer siteBookings = siteClient.queryByCode(code); |
| | | // List<Integer> stores = new ArrayList<>(); |
| | | // stores.add(coursePackagePayments); |
| | | // stores.add(paymentCompetitions); |
| | | // stores.add(siteBookings); |
| | | // |
| | | // OperatorUser operatorUser = siteClient.queryOperator(stores); |
| | | // |
| | | // |
| | | //// WxPayService myWxPayService = wxPayService.switchoverTo("mch_id"); |
| | | //// |
| | | //// ProfitSharingV3Service profitSharingV3Service = myWxPayService.getProfitSharingV3Service(); |
| | | // |
| | | // String nonceStr = RandomUtil.randomString(32); |
| | | // String appId = "您的appid"; |
| | | // |
| | | // |
| | | // //添加分账方 |
| | | // |
| | | //// ProfitSharingReceiver profitSharingReceiver = new ProfitSharingReceiver(); |
| | | //// profitSharingReceiver.setAccount("appid对应的openId"); |
| | | //// profitSharingReceiver.setAmount(1l); |
| | | //// profitSharingReceiver.setAppid(appId); |
| | | //// profitSharingReceiver.setType("PERSONAL_OPENID"); |
| | | //// profitSharingReceiver.setRelationType("PARTNER"); |
| | | //// profitSharingV3Service.addProfitSharingReceiver(profitSharingReceiver); |
| | | // |
| | | // //分账 |
| | | // ProfitSharingRequest profitSharingRequest = new ProfitSharingRequest(); |
| | | // profitSharingRequest.setAppid(appId); |
| | | // profitSharingRequest.setTransactionId("微信支付订单号"); |
| | | // profitSharingRequest.setOutOrderNo("业务系统唯一编号"); |
| | | // //分账完成后,剩余金额自动解冻并返回给商户账号,默认false |
| | | // profitSharingRequest.setUnfreezeUnsplit(true); |
| | | // //待分账金额1元 |
| | | // Long money = 1L; |
| | | // List<ProfitSharingReceiver> profitSharingReceivers = new ArrayList<>(); |
| | | // ProfitSharingReceiver profitSharingReceiver = new ProfitSharingReceiver(); |
| | | // profitSharingReceiver.setAccount("appid对应的openId,分账用户1"); |
| | | // |
| | | // |
| | | // //分账百分之5 |
| | | // profitSharingReceiver.setAmount(money * 100 / 5); |
| | | // profitSharingReceiver.setAppid(appId); |
| | | // profitSharingReceiver.setType("PERSONAL_OPENID"); |
| | | // profitSharingReceiver.setRelationType("PARTNER"); |
| | | // profitSharingReceiver.setDescription("test01"); |
| | | // profitSharingReceivers.add(profitSharingReceiver); |
| | | // |
| | | // ProfitSharingReceiver receiver = new ProfitSharingReceiver(); |
| | | // receiver.setAccount("appid对应的openId,分账用户2"); |
| | | // //百分之10 |
| | | // receiver.setAmount(money * 100 / 10); |
| | | // receiver.setAppid(appId); |
| | | // receiver.setType("PERSONAL_OPENID"); |
| | | // receiver.setRelationType("PARTNER"); |
| | | // receiver.setDescription("test02"); |
| | | // profitSharingReceivers.add(receiver); |
| | | // |
| | | // |
| | | // profitSharingRequest.setReceivers(profitSharingReceivers); |
| | | // |
| | | // profitSharingV3Service.profitSharing(profitSharingRequest); |
| | | // |
| | | // |
| | | // |
| | | // |
| | | //// Map<String,String> headers = new HashMap<>(); |
| | | //// headers.put("Authorization",map.get("sign")); |
| | | //// headers.put("Accept","application/json"); |
| | | //// headers.put("Wechatpay-Serial",certPath); |
| | | //// |
| | | //// List<Receivers> receivers = new ArrayList<>(); |
| | | //// |
| | | //// Map<String,Object> body = new HashMap<>(); |
| | | //// body.put("appid",appid); |
| | | //// body.put("transaction_id",map.get("transaction_id")); |
| | | //// body.put("out_order_no",map.get("out_trade_no")); |
| | | //// body.put("receivers",receivers); |
| | | //// body.put("unfreeze_unsplit",true); |
| | | // |
| | | // //支付分账 |
| | | //// String url ="https://api.mch.weixin.qq.com/v3/profitsharing/orders"; |
| | | //// CloseableHttpResponse closeableHttpResponse = HttpClientUtil.setPostHttpRequset(url, body, headers, "application/json"); |
| | | //// |
| | | // |
| | | // return null; |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // } |
| | | |
| | | /** |
| | | * 微信扫码收款 |
| | |
| | | } |
| | | |
| | | |
| | | public static void main(String[] ages){ |
| | | PayMoneyUtil payMoneyUtil = new PayMoneyUtil(); |
| | | ResultUtil ce = payMoneyUtil.alipay("测试", "", "", "121456457", "10", "http://123.com"); |
| | | System.err.println(ce); |
| | | ResultUtil resultUtil = null; |
| | | try { |
| | | resultUtil = payMoneyUtil.queryALIOrder("121456457"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | System.err.println(resultUtil); |
| | | } |
| | | // public static void main(String[] ages){ |
| | | // PayMoneyUtil payMoneyUtil = new PayMoneyUtil(); |
| | | // ResultUtil ce = payMoneyUtil.alipay("测试", "测试", "", "121456457", "10", "http://123.com"); |
| | | // System.err.println(ce); |
| | | // ResultUtil resultUtil = null; |
| | | // try { |
| | | // resultUtil = payMoneyUtil.queryALIOrder("121456457"); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // System.err.println(resultUtil); |
| | | // } |
| | | |
| | | |
| | | /** |