微信支付之企业付款(提现,理赔,退款)(java)
生活随笔
收集整理的這篇文章主要介紹了
微信支付之企业付款(提现,理赔,退款)(java)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** 提現操作* @throws Exception */@RequestMapping("doCash")public String doTravelScoreCash(HttpServletRequest request) throws Exception {//微信企業付款 接口url https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfersString company_pay_url = ConstantUtil.COMPANY_PAY_URL;String openid = (String) this.getSession().getAttribute("customerOpenId");//用戶String mch_appid = ConstantUtil.APPID;String mch_id = ConstantUtil.MCH_ID;String device_info = ConstantUtil.DEVICE_INFO;String nonce_str = WXPayUtil.generateNonceStr();String partner_trade_no = DateUtils.fmtTime14Date(new Date());//商戶訂單號String check_name = "NO_CHECK";//校驗用戶姓名選項 // NO_CHECK:不校驗真實姓名 FORCE_CHECK:強校驗真實姓名String re_user_name = "王小王";//收款用戶真實姓名 //如果check_name設置為FORCE_CHECK,則必填用戶真實姓名String amount = "1";//企業付款總金額數(分)String desc = "旅游基金";//企業付款描述信息String spbill_create_ip = request.getRemoteAddr();//調用接口的終端ipMap<String, String> data = new HashMap<String, String>();data.put("mch_appid", mch_appid); //商戶號data.put("mchid",mch_id);//注意這里沒下劃線 ,我都不想說什么了,微信支付的時候這里是帶下劃線的,data.put("device_info",device_info);data.put("nonce_str",nonce_str); data.put("partner_trade_no",partner_trade_no); data.put("openid",openid);data.put("check_name",check_name);data.put("re_user_name",re_user_name);data.put("amount",amount);data.put("desc",desc);data.put("spbill_create_ip",spbill_create_ip);String sign = WXPayUtil.generateSignature(data,ConstantUtil.APPKEY);data.put("sign",sign);//***********************企業付款請求*********************************KeyStore keyStore = KeyStore.getInstance("PKCS12");String certPath = "C://apiclient_cert.p12";FileInputStream instream = new FileInputStream(new File(certPath));try {keyStore.load(instream,mch_id.toCharArray());} finally {instream.close();}// Trust own CA and all self-signed certsSSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mch_id.toCharArray()).build();// Allow TLSv1 protocol onlySSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,new String[] { "TLSv1" },null,SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();try {HttpPost httpPost = new HttpPost(company_pay_url);httpPost.addHeader("Connection", "keep-alive");httpPost.addHeader("Accept", "*/*");httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");httpPost.addHeader("Host", "api.mch.weixin.qq.com");httpPost.addHeader("X-Requested-With", "XMLHttpRequest");httpPost.addHeader("Cache-Control", "max-age=0");httpPost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");String dataXML = WXPayUtil.mapToXml(data);httpPost.setEntity(new StringEntity(dataXML, "UTF-8"));System.out.println("執行請求" + httpPost.getRequestLine());CloseableHttpResponse response = httpclient.execute(httpPost);try {HttpEntity entity = response.getEntity();System.out.println("----------------------------------------");System.out.println(response.getStatusLine());//相應狀態碼if (entity != null) {System.out.println("響應內容長度: " + entity.getContentLength());BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent(),"UTF-8"));String text;while ((text = bufferedReader.readLine()) != null) {System.out.println(text);}}EntityUtils.consume(entity);} finally {response.close();}} finally {httpclient.close();}return "redirect:"+Global.getAdminPath()+"/home/index.do";//進入提現進度頁面}
總結
以上是生活随笔為你收集整理的微信支付之企业付款(提现,理赔,退款)(java)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 5张图看懂如何实现Windows RTM
- 下一篇: 【NLP】国内实力雄厚的自然语言处理(N