From 6efc676c6599cee0f82989fbda0e6bbdd71b9bfe Mon Sep 17 00:00:00 2001
From: ChenJiaHe <763432473@qq.com>
Date: 星期一, 19 四月 2021 11:50:52 +0800
Subject: [PATCH] 新增企业付款接口(优化)

---
 /dev/null                                             |  132 -------
 src/main/java/com/hx/corp/entity/CorpPayRequest.java  |  135 +++++++
 src/main/java/com/hx/corp/entity/CorpPayResponse.java |  132 +++++++
 src/main/java/com/hx/corp/util/WxCorpPayUtil.java     |  610 +++++++++++++++++++++++++++++++++++
 4 files changed, 877 insertions(+), 132 deletions(-)

diff --git a/hx-common.iml b/hx-common.iml
deleted file mode 100644
index ad4fe96..0000000
--- a/hx-common.iml
+++ /dev/null
@@ -1,132 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
-  <component name="FacetManager">
-    <facet type="Spring" name="Spring">
-      <configuration />
-    </facet>
-    <facet type="web" name="Web">
-      <configuration>
-        <webroots />
-      </configuration>
-    </facet>
-  </component>
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
-    <output url="file://$MODULE_DIR$/target/classes" />
-    <output-test url="file://$MODULE_DIR$/target/test-classes" />
-    <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
-      <excludeFolder url="file://$MODULE_DIR$/target" />
-    </content>
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="library" name="Maven: com.qcloud:cos_api:5.6.24" level="project" />
-    <orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
-    <orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:3.9" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:3.9" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:2.3.0" level="project" />
-    <orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" />
-    <orderEntry type="library" name="Maven: dom4j:dom4j:2.1.3" level="project" />
-    <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
-    <orderEntry type="library" name="Maven: com.qcloud:cos_api:5.6.32" level="project" />
-    <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
-    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" />
-    <orderEntry type="library" name="Maven: joda-time:joda-time:2.9.9" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
-    <orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.6.2" level="project" />
-    <orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.6" level="project" />
-    <orderEntry type="library" name="Maven: com.aliyun.oss:aliyun-sdk-oss:2.8.3" level="project" />
-    <orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.66" level="project" />
-    <orderEntry type="library" name="Maven: org.dom4j:dom4j:2.1.3" level="project" />
-    <orderEntry type="library" name="Maven: org.jdom:jdom:1.1.3" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.13" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.12" level="project" />
-    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
-    <orderEntry type="library" name="Maven: cglib:cglib:3.1" level="project" />
-    <orderEntry type="library" name="Maven: org.ow2.asm:asm:4.2" level="project" />
-    <orderEntry type="library" name="Maven: com.google.zxing:core:3.3.0" level="project" />
-    <orderEntry type="library" name="Maven: net.glxn:qrgen:1.4" level="project" />
-    <orderEntry type="library" name="Maven: com.google.zxing:javase:3.0.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.9" level="project" />
-    <orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.poi:poi:3.9" level="project" />
-    <orderEntry type="library" name="Maven: redis.clients:jedis:2.9.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.5.0" level="project" />
-    <orderEntry type="library" name="Maven: com.auth0:java-jwt:3.10.3" level="project" />
-    <orderEntry type="library" name="Maven: io.jsonwebtoken:jjwt:0.9.1" level="project" />
-    <orderEntry type="library" name="Maven: javax.servlet.jsp.jstl:jstl-api:1.2" level="project" />
-    <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.5" level="project" />
-    <orderEntry type="library" name="Maven: javax.servlet.jsp:jsp-api:2.1" level="project" />
-    <orderEntry type="library" name="Maven: javax.servlet:jstl:1.2" level="project" />
-    <orderEntry type="library" name="Maven: com.gitee.sunchenbin.mybatis.actable:mybatis-enhance-actable:1.1.1.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.28" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:1.4.2.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.0.10.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:2.0.10.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.0.10.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-tx:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-oxm:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.0.5.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.0.5.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.0.5.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.19" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.0.5.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.6" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.6" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.6" level="project" />
-    <orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.12.Final" level="project" />
-    <orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" />
-    <orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.4" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-web:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1" level="project" />
-    <orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:1.1.1" level="project" />
-    <orderEntry type="library" name="Maven: org.mybatis:mybatis:3.4.0" level="project" />
-    <orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:1.3.0" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.0.5.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: com.zaxxer:HikariCP:2.7.9" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.0.9.RELEASE" level="project" />
-    <orderEntry type="library" scope="RUNTIME" name="Maven: mysql:mysql-connector-java:5.1.47" level="project" />
-    <orderEntry type="library" name="Maven: com.alibaba:druid:1.1.9" level="project" />
-    <orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.47" level="project" />
-    <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
-    <orderEntry type="library" name="Maven: net.sf.json-lib:json-lib:jdk15:2.4" level="project" />
-    <orderEntry type="library" name="Maven: com.belerweb:pinyin4j:2.5.1" level="project" />
-    <orderEntry type="library" name="Maven: net.sourceforge.jexcelapi:jxl:2.6.12" level="project" />
-    <orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" />
-    <orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.3" level="project" />
-    <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
-    <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" />
-    <orderEntry type="library" name="Maven: net.sf.ezmorph:ezmorph:1.0.3" level="project" />
-    <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
-    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
-    <orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.1.11" level="project" />
-    <orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:2.0" level="project" />
-    <orderEntry type="library" name="Maven: com.dtflys.forest:spring-boot-starter-forest:1.5.0-RC2" level="project" />
-    <orderEntry type="library" name="Maven: com.dtflys.forest:forest-core:1.5.0-RC2" level="project" />
-    <orderEntry type="library" name="Maven: com.googlecode.juniversalchardet:juniversalchardet:1.0.3" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient-cache:4.5.12" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.12" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.4.13" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.1.4" level="project" />
-    <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.14.9" level="project" />
-    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.17.2" level="project" />
-    <orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.1" level="project" />
-    <orderEntry type="library" name="Maven: com.dtflys.forest:forest-spring:1.5.0-RC2" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-configuration-processor:2.0.5.RELEASE" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.6" level="project" />
-  </component>
-</module>
\ No newline at end of file
diff --git a/src/main/java/com/hx/corp/entity/CorpPayRequest.java b/src/main/java/com/hx/corp/entity/CorpPayRequest.java
new file mode 100644
index 0000000..88f9859
--- /dev/null
+++ b/src/main/java/com/hx/corp/entity/CorpPayRequest.java
@@ -0,0 +1,135 @@
+package com.hx.corp.entity;
+
+import java.util.UUID;
+
+/**浼佷笟浠樻璇锋眰鍙傛暟瀹炰綋
+ *
+ */
+public class CorpPayRequest {
+
+    /*锛圷锛夊晢鎴疯处鍙穉ppid锛岀敵璇峰晢鎴峰彿鐨刟ppid鎴栧晢鎴峰彿缁戝畾鐨刟ppid*/
+    private String mch_appid;
+    /*(Y)鍟嗘埛鍙�*/
+    private String mchid;
+    /*(N)璁惧鍙�*/
+    private String device_info;
+    /*(Y)闅忔満瀛楃涓�*/
+    private String nonce_str = UUID.randomUUID().toString().substring(0, 30);
+    /*(Y)闅忕鍚�*/
+    private String sign;
+    /*(Y)鍟嗘埛璁㈠崟鍙�*/
+    private String partner_trade_no;
+    /*(Y)鐢ㄦ埛openid*/
+    private String openid;
+    /*(Y)鏍¢獙鐢ㄦ埛濮撳悕閫夐」锛孨O_CHECK锛氫笉鏍¢獙鐪熷疄濮撳悕 锛汧ORCE_CHECK锛氬己鏍¢獙鐪熷疄濮撳悕*/
+    private String check_name = "NO_CHECK";
+    /*(O)鏀舵鐢ㄦ埛濮撳悕,濡傛灉check_name璁剧疆涓篎ORCE_CHECK锛屽垯蹇呭~鐢ㄦ埛鐪熷疄濮撳悕*/
+    private String re_user_name;
+    /*(Y)閲戦*/
+    private int amount;
+    /*(Y)浼佷笟浠樻澶囨敞*/
+    private String desc;
+    /*(N)Ip鍦板潃锛岃IP鍚屽湪鍟嗘埛骞冲彴璁剧疆鐨処P鐧藉悕鍗曚腑鐨処P娌℃湁鍏宠仈锛岃IP鍙紶鐢ㄦ埛绔垨鑰呮湇鍔$鐨処P*/
+    private String spbill_create_ip = "8.8.8.8";
+
+    public CorpPayRequest() {
+    }
+
+    ////////////////////////////////////////////////////////
+
+    public String getMch_appid() {
+        return mch_appid;
+    }
+
+    public void setMch_appid(String mch_appid) {
+        this.mch_appid = mch_appid;
+    }
+
+    public String getMchid() {
+        return mchid;
+    }
+
+    public void setMchid(String mchid) {
+        this.mchid = mchid;
+    }
+
+    public String getDevice_info() {
+        return device_info;
+    }
+
+    public void setDevice_info(String device_info) {
+        this.device_info = device_info;
+    }
+
+    public String getSign() {
+        return sign;
+    }
+
+    public void setSign(String sign) {
+        this.sign = sign;
+    }
+
+    public String getPartner_trade_no() {
+        return partner_trade_no;
+    }
+
+    public void setPartner_trade_no(String partner_trade_no) {
+        this.partner_trade_no = partner_trade_no;
+    }
+
+    public String getOpenid() {
+        return openid;
+    }
+
+    public void setOpenid(String openid) {
+        this.openid = openid;
+    }
+
+    public String getCheck_name() {
+        return check_name;
+    }
+
+    public void setCheck_name(String check_name) {
+        this.check_name = check_name;
+    }
+
+    public String getRe_user_name() {
+        return re_user_name;
+    }
+
+    public void setRe_user_name(String re_user_name) {
+        this.re_user_name = re_user_name;
+    }
+
+    public int getAmount() {
+        return amount;
+    }
+
+    public void setAmount(int amount) {
+        this.amount = amount;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+    }
+
+    public String getSpbill_create_ip() {
+        return spbill_create_ip;
+    }
+
+    public void setSpbill_create_ip(String spbill_create_ip) {
+        this.spbill_create_ip = spbill_create_ip;
+    }
+
+    public String getNonce_str() {
+        return nonce_str;
+    }
+
+    public void setNonce_str(String nonce_str) {
+        this.nonce_str = nonce_str;
+    }
+}
diff --git a/src/main/java/com/hx/corp/entity/CorpPayResponse.java b/src/main/java/com/hx/corp/entity/CorpPayResponse.java
new file mode 100644
index 0000000..723c3fc
--- /dev/null
+++ b/src/main/java/com/hx/corp/entity/CorpPayResponse.java
@@ -0,0 +1,132 @@
+package com.hx.corp.entity;
+
+/**浼佷笟浠樻杩斿洖鍙傛暟瀹炰綋
+ *
+ */
+public class CorpPayResponse {
+
+    /*(Y)涓氬姟缁撴灉锛孲UCCESS/FAIL锛屾敞鎰忥細褰撶姸鎬佷负FAIL鏃讹紝瀛樺湪涓氬姟缁撴灉鏈槑纭殑鎯呭喌銆傚鏋滅姸鎬佷负FAIL锛岃鍔″繀鍏虫敞閿欒浠g爜锛坋rr_code瀛楁锛夛紝閫氳繃鏌ヨ鎺ュ彛纭姝ゆ浠樻鐨勭粨鏋�*/
+    private String result_code = "FAIL";
+    /*锛圷锛夐敊璇唬鐮侊紝鎴愬姛锛歋UCCESS*/
+    private String err_code;
+    /*(Y)閿欒浠g爜鎻忚堪*/
+    private String err_code_des;
+    /*(Y)鍟嗘埛appid*/
+    private String mch_appid;
+    /*(Y)鍟嗘埛鍙�*/
+    private String mchid;
+    /*(N)璁惧鍙�*/
+    private String device_info;
+    /*(Y)闅忔満瀛楃涓�*/
+    private String nonce_str;
+
+    //浠ヤ笅瀛楁鍦╮eturn_code 鍜宺esult_code閮戒负SUCCESS鐨勬椂鍊欐湁杩斿洖
+    /*(O)鍟嗘埛璁㈠崟鍙�*/
+    private String partner_trade_no;
+    /*(O)鍟嗘埛璁㈠崟鍙�*/
+    private String payment_no;
+    /*(O)浠樻鎴愬姛鏃堕棿*/
+    private String payment_time;
+
+
+    public CorpPayResponse() {
+    }
+
+    ////////////////////////////////////////////////////////
+
+    public String getMch_appid() {
+        return mch_appid;
+    }
+
+    public void setMch_appid(String mch_appid) {
+        this.mch_appid = mch_appid;
+    }
+
+    public String getMchid() {
+        return mchid;
+    }
+
+    public void setMchid(String mchid) {
+        this.mchid = mchid;
+    }
+
+    public String getDevice_info() {
+        return device_info;
+    }
+
+    public void setDevice_info(String device_info) {
+        this.device_info = device_info;
+    }
+
+    public String getResult_code() {
+        return result_code;
+    }
+
+    public void setResult_code(String result_code) {
+        this.result_code = result_code;
+    }
+
+    public String getErr_code() {
+        return err_code;
+    }
+
+    public void setErr_code(String err_code) {
+        this.err_code = err_code;
+    }
+
+    public String getErr_code_des() {
+        return err_code_des;
+    }
+
+    public void setErr_code_des(String err_code_des) {
+        this.err_code_des = err_code_des;
+    }
+
+    public String getNonce_str() {
+        return nonce_str;
+    }
+
+    public void setNonce_str(String nonce_str) {
+        this.nonce_str = nonce_str;
+    }
+
+    public String getPartner_trade_no() {
+        return partner_trade_no;
+    }
+
+    public void setPartner_trade_no(String partner_trade_no) {
+        this.partner_trade_no = partner_trade_no;
+    }
+
+    public String getPayment_no() {
+        return payment_no;
+    }
+
+    public void setPayment_no(String payment_no) {
+        this.payment_no = payment_no;
+    }
+
+    public String getPayment_time() {
+        return payment_time;
+    }
+
+    public void setPayment_time(String payment_time) {
+        this.payment_time = payment_time;
+    }
+
+    @Override
+    public String toString() {
+        return "CorpPayResponse{" +
+                "result_code='" + result_code + '\'' +
+                ", err_code='" + err_code + '\'' +
+                ", err_code_des='" + err_code_des + '\'' +
+                ", mch_appid='" + mch_appid + '\'' +
+                ", mchid='" + mchid + '\'' +
+                ", device_info='" + device_info + '\'' +
+                ", nonce_str='" + nonce_str + '\'' +
+                ", partner_trade_no='" + partner_trade_no + '\'' +
+                ", payment_no='" + payment_no + '\'' +
+                ", payment_time='" + payment_time + '\'' +
+                '}';
+    }
+}
diff --git a/src/main/java/com/hx/corp/util/WxCorpPayUtil.java b/src/main/java/com/hx/corp/util/WxCorpPayUtil.java
new file mode 100644
index 0000000..9f29441
--- /dev/null
+++ b/src/main/java/com/hx/corp/util/WxCorpPayUtil.java
@@ -0,0 +1,610 @@
+package com.hx.corp.util;
+
+import com.alibaba.fastjson.JSON;
+import com.hx.corp.entity.CorpPayRequest;
+import com.hx.corp.entity.CorpPayResponse;
+import com.hx.exception.ServiceException;
+import com.hx.mp.util.*;
+import com.hx.util.SimpleTool;
+import com.hx.util.StringUtils;
+import net.sf.json.JSONObject;
+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.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.net.ssl.SSLContext;
+import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.FileInputStream;
+import java.security.KeyStore;
+import java.util.*;
+
+
+/** 浼佷笟寰俊鏀粯/閫�娆�
+ * @author ChenJiaHe
+ */
+public class WxCorpPayUtil {
+
+    //log4j鏃ュ織
+    private static Logger logger = LoggerFactory.getLogger(WxCorpPayUtil.class.getName());
+
+    // 閫�娆炬帴鍙h繛鎺�
+    private static final String REFUND_URL = "https://api.mch.weixin.qq.com/secapi/pay/refund";
+     /**鏌ヨ璁㈠崟閾炬帴*/
+    @SuppressWarnings("unused")
+    private static final String QUERY_URL = "https://api.mch.weixin.qq.com/pay/orderquery";
+    /**鍚屾剰涓嬪崟閾炬帴*/
+    private static final String FIRST_ORDER_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder";
+
+    // 浼佷笟浠樻
+    private static final String CORP_PAY_URL = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
+
+
+    /** 浼佷笟浠樻
+     * @param corpPayRequest 璇锋眰瀵硅薄
+     * @param mchKey 鍟嗘埛鍙风閽�
+     * @param certPath 鏀粯璇佷功
+     * @return CorpPayResponse
+     * @throws Exception
+     */
+    public static CorpPayResponse qdCorpPay(CorpPayRequest corpPayRequest, String mchKey, String certPath)
+            throws Exception {
+
+        CorpPayResponse corpPayResponse = new CorpPayResponse();
+
+        SortedMap<Object, Object> parameters = new TreeMap<Object, Object>();
+        parameters.put("mch_appid", corpPayRequest.getMch_appid());
+        parameters.put("mchid", corpPayRequest.getMchid());
+        parameters.put("partner_trade_no", corpPayRequest.getPartner_trade_no());
+        //parameters.put("nonce_str", UUID.randomUUID().toString().substring(0, 30));
+        parameters.put("nonce_str", corpPayRequest.getNonce_str());
+        parameters.put("openid", corpPayRequest.getOpenid());
+        parameters.put("check_name", corpPayRequest.getCheck_name());
+        parameters.put("amount", corpPayRequest.getAmount());
+        parameters.put("spbill_create_ip", corpPayRequest.getSpbill_create_ip());
+        parameters.put("desc", corpPayRequest.getDesc());
+
+        String sign = WXSignUtils.createSign("UTF-8", parameters, mchKey);
+
+        parameters.put("sign", sign);
+        String xmlInfo = HttpXmlUtils.transferXml(parameters);
+
+        try {
+            CloseableHttpResponse response = HttpUtil.Post(CORP_PAY_URL, xmlInfo, true, certPath, corpPayRequest.getMchid());
+            String transfersXml = EntityUtils.toString(response.getEntity(), "utf-8");
+            // System.out.println("娓犻亾绔紒涓氫粯娆撅細" + transfersXml);
+            Map<String, String> transferMap = HttpXmlUtils.parseRefundXml(transfersXml);
+            // 灏� Map 杞崲涓� 瀹炰綋绫�
+            corpPayResponse = JSON.parseObject(JSON.toJSONString(transferMap),CorpPayResponse.class);
+        } catch (Exception e) {
+            logger.error("浼佷笟浠樻鎺ュ彛鎶ラ敊",e);
+        }
+        return corpPayResponse;
+    }
+
+
+    /**缁熶竴鏀粯
+     * @param request 鏂规硶鑾峰彇
+     * @param appId  灏忕▼搴忓彿
+     * @param partner  鍟嗘埛鍙�
+     * @param key  绉橀挜
+     * @param notifyUrl  鍥炶皟閾炬帴
+     * @param out_trade_no  璁㈠崟鍙�
+     * @param body 鍟嗗搧鎻忚堪
+     * @param total_fee 鏀粯閲戦
+     * @param openid 鐢ㄦ埛openId
+     * @param attach 闄勫甫鏁版嵁鍖�
+     * @param notifyUrl 鍥炶皟閫氱煡鍦板潃
+     * @param trade_type 浜ゆ槗绫诲瀷
+     * @return JSON  status = "SUC"涓烘垚鍔�
+     */
+    public static JSONObject unifiedPay(HttpServletRequest request,String appId,String partner,String key,String notifyUrl,String out_trade_no, String body, String total_fee, String openid,
+            String attach,String trade_type) throws Exception {
+
+        if (!SimpleTool.checkNotNull(notifyUrl)) {
+            throw new ServiceException("鏀粯鍔熻兘鏁呴殰锛�");
+        }
+
+        // 鍒涘缓鏌ヨ璇锋眰瀵硅薄
+        RequestHandler reqHandler = new RequestHandler(null, null);
+        // 閫氫俊瀵硅薄
+        TenpayHttpClient httpClient = new TenpayHttpClient();
+        // 搴旂瓟瀵硅薄
+        ClientResponseHandler resHandler = new ClientResponseHandler();
+
+        // -----------------------------
+        // 璁剧疆璇锋眰鍙傛暟
+        // -----------------------------
+        // reqHandler.init();
+        reqHandler.setKey(key);
+        reqHandler.setGateUrl(FIRST_ORDER_URL);// 璇锋眰URL
+
+        // -----------------------------
+        // 璁剧疆鎺ュ彛鍙傛暟(sign鍚庡彴鑷姩鐢熸垚)
+        // -----------------------------
+        reqHandler.setParameter("appid", appId); // 鍏紬鍙�/灏忕▼搴�
+        reqHandler.setParameter("mch_id", partner); // 鍟嗘埛鍙�
+        reqHandler.setParameter("nonce_str", SimpleTool.getUUIDName().substring(0, 30));// 闅忔満涔辩爜
+        reqHandler.setParameter("body", body);// 鍟嗗搧鎻忚堪
+        reqHandler.setParameter("out_trade_no", out_trade_no);// 鍟嗘埛璁㈠崟鍙�
+        reqHandler.setParameter("total_fee", total_fee);// 鎬婚噾棰�
+        reqHandler.setParameter("spbill_create_ip", "8.8.8.8");// 缁堢IP
+        reqHandler.setParameter("notify_url",notifyUrl);// 閫氱煡鍦板潃
+        reqHandler.setParameter("trade_type", trade_type);// 浜ゆ槗绫诲瀷
+                                                          // JSAPI锛孨ATIVE锛孉PP
+        reqHandler.setParameter("openid", openid);// openId
+        reqHandler.setParameter("attach", attach);// 闄勫甫鏁版嵁鍖�
+
+        // -----------------------------
+        // 璁剧疆閫氫俊鍙傛暟
+        // -----------------------------
+        // 璁剧疆璇锋眰杩斿洖鐨勭瓑寰呮椂闂�
+        httpClient.setTimeOut(5);
+
+        // 璁剧疆ca璇佷功
+        // httpClient.setCaInfo(new File(CA_PATH));
+
+        // 璁剧疆涓汉(鍟嗘埛)璇佷功
+        // httpClient.setCertInfo(new File(CERT_PATH), CERT_PWD);
+
+        // 璁剧疆鍙戦�佺被鍨婸OST
+        httpClient.setMethod("POST");
+
+        // 璁剧疆璇锋眰鍐呭(鐢熸垚sign)
+        String requestUrl = reqHandler.getRequestURL();// 缁勬嫾https://www.baidu.com?a=x&b=xx
+
+        httpClient.setReqContent(requestUrl);// https://www.baidu.com?a=x&b=xx
+        String rescontent = "null";
+
+        httpClient.setRequestHandler(reqHandler);// 鎶婂鐞嗗璞★紝鍍忔槸鍙傛暟鍚勭涓滆タ閮借缃繘鍘绘柟渚胯幏鍙�(quan)
+
+        // 杩斿洖鍑哄幓鐨勫璞�(鐘舵�侊紝閿欒鍘熷洜锛岃鎿嶄綔鐩稿叧淇℃伅(鍙傛暟,杩斿洖鍊�))
+        JSONObject returnObj = new JSONObject();
+
+        // 鍚庡彴璋冪敤
+        if (httpClient.call()) {
+            System.out.println("缁熶竴涓嬪崟,鎴愬姛cll浜�::");
+
+            // 璁剧疆缁撴灉鍙傛暟
+            rescontent = httpClient.getResContent();
+            System.out.println("缁熶竴涓嬪崟杩斿洖缁撴灉:" + rescontent);
+            resHandler.setContent(rescontent);// 瑙f瀽xml
+            resHandler.setKey(key);
+
+            // 鑾峰彇杩斿洖鍙傛暟
+            String return_code = resHandler.getParameter("return_code");
+            String return_msg = resHandler.getParameter("return_msg");
+
+            // 鍒ゆ柇绛惧悕鍙婄粨鏋�
+            if (resHandler.isTenpaySign() && "SUCCESS".equals(return_code)) {
+                String prepay_id = resHandler.getParameter("prepay_id");// 棰勬敮浠樹氦鏄撲細璇濇爣璇�
+                String code_url = resHandler.getParameter("code_url");// 浜岀淮鐮侀摼鎺�
+
+                String result_code = resHandler.getParameter("result_code");// 涓氬姟缁撴灉
+                String appid = resHandler.getParameter("appid");// 鍏紬璐﹀彿ID
+                String mch_id = resHandler.getParameter("mch_id");// 鍟嗘埛鍙�
+                String nonce_str = resHandler.getParameter("nonce_str");// 闅忔満鐮�
+                String sign = resHandler.getParameter("sign");// 绛惧悕
+
+                if (result_code.equals("SUCCESS")) {
+                    returnObj.put("status", "suc");
+                    returnObj.put("sign", sign);
+                    returnObj.put("nonce_str", nonce_str);
+                    returnObj.put("mch_id", mch_id);
+                    returnObj.put("appid", appid);
+                    returnObj.put("prepay_id", prepay_id);
+                    returnObj.put("code_url", code_url);
+                    returnObj.put("out_trade_no", out_trade_no);
+                } else {
+                    String errMsg = "[ERROR]result_code:" + resHandler.getParameter("result_code") + " err_code:"
+                            + resHandler.getParameter("err_code") + "err_code_des:"
+                            + resHandler.getParameter("err_code_des");
+
+                    // 閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫��
+                    returnObj.put("status", "ERROR-C");
+                    returnObj.put("errMsg", errMsg);
+                }
+            } else {
+                String errMsg = "return_code:" + return_code + "err_code:" + resHandler.getParameter("err_code")
+                        + " return_msg:" + return_msg;
+                // 閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫��
+                returnObj.put("status", "ERROR-B");
+                returnObj.put("errMsg", errMsg);
+            }
+        } else {
+            // 鏈夊彲鑳藉洜涓虹綉缁滃師鍥狅紝璇锋眰宸茬粡澶勭悊锛屼絾鏈敹鍒板簲绛斻��
+            returnObj.put("status", "ERROR-A");
+            returnObj.put("errMsg", httpClient.getResponseCode() + ":" + httpClient.getErrInfo());
+        }
+
+        // 鑾峰彇debug淇℃伅,寤鸿鎶婅姹傘�佸簲绛斿唴瀹广�乨ebug淇℃伅锛岄�氫俊杩斿洖鐮佸啓鍏ユ棩蹇楋紝鏂逛究瀹氫綅闂
+        String detail = "http res:" + httpClient.getResponseCode() + "," + httpClient.getErrInfo() + ";" + "req url:"
+                + requestUrl + ";" + ";" + "req debug:" + reqHandler.getDebugInfo() + ";" + "res content:" + rescontent
+                + ";" + "res debug:" + resHandler.getDebugInfo() + ";";
+
+        returnObj.put("detail", detail);
+
+        
+        return returnObj;
+    }
+
+    /**缁熶竴鏀粯锛堝垎璐︼級
+     * @param request 鏂规硶鑾峰彇
+     * @param appId  灏忕▼搴忓彿
+     * @param partner  鍟嗘埛鍙�
+     * @param key  绉橀挜
+     * @param notifyUrl  鍥炶皟閾炬帴
+     * @param out_trade_no  璁㈠崟鍙�
+     * @param body 鍟嗗搧鎻忚堪
+     * @param total_fee 鏀粯閲戦
+     * @param openid 鐢ㄦ埛openId
+     * @param attach 闄勫甫鏁版嵁鍖�
+     * @param notifyUrl 鍥炶皟閫氱煡鍦板潃
+     * @param trade_type 浜ゆ槗绫诲瀷
+     * @param profit_sharing 鏄惁鍒嗚处锛歂涓嶏紝Y鏄�
+     * @return JSON  status = "SUC"涓烘垚鍔�
+     */
+    public static JSONObject unifiedPay(HttpServletRequest request,String appId,String partner,String key,String notifyUrl,String out_trade_no, String body, String total_fee, String openid,
+                                        String attach,String trade_type,String profit_sharing) throws Exception {
+
+        if (!SimpleTool.checkNotNull(notifyUrl)) {
+            throw new ServiceException("鏀粯鍔熻兘鏁呴殰锛�");
+        }
+
+        // 鍒涘缓鏌ヨ璇锋眰瀵硅薄
+        RequestHandler reqHandler = new RequestHandler(null, null);
+        // 閫氫俊瀵硅薄
+        TenpayHttpClient httpClient = new TenpayHttpClient();
+        // 搴旂瓟瀵硅薄
+        ClientResponseHandler resHandler = new ClientResponseHandler();
+
+        // -----------------------------
+        // 璁剧疆璇锋眰鍙傛暟
+        // -----------------------------
+        // reqHandler.init();
+        reqHandler.setKey(key);
+        reqHandler.setGateUrl(FIRST_ORDER_URL);// 璇锋眰URL
+
+        // -----------------------------
+        // 璁剧疆鎺ュ彛鍙傛暟(sign鍚庡彴鑷姩鐢熸垚)
+        // -----------------------------
+
+        reqHandler.setParameter("appid", appId); // 鍏紬鍙�/灏忕▼搴�
+        reqHandler.setParameter("mch_id", partner); // 鍟嗘埛鍙�
+        reqHandler.setParameter("nonce_str", SimpleTool.getUUIDName().substring(0, 30));// 闅忔満涔辩爜
+        reqHandler.setParameter("body", body);// 鍟嗗搧鎻忚堪
+        reqHandler.setParameter("out_trade_no", out_trade_no);// 鍟嗘埛璁㈠崟鍙�
+        reqHandler.setParameter("total_fee", total_fee);// 鎬婚噾棰�
+        reqHandler.setParameter("spbill_create_ip", "8.8.8.8");// 缁堢IP
+        reqHandler.setParameter("notify_url",notifyUrl);// 閫氱煡鍦板潃
+        reqHandler.setParameter("trade_type", trade_type);// 浜ゆ槗绫诲瀷
+        //JSAPI锛孨ATIVE锛孉PP
+        reqHandler.setParameter("openid", openid);// openId
+        reqHandler.setParameter("attach", attach);// 闄勫甫鏁版嵁鍖�
+        reqHandler.setParameter("profit_sharing", profit_sharing);// 闄勫甫鏁版嵁鍖�
+
+        // -----------------------------
+        // 璁剧疆閫氫俊鍙傛暟
+        // -----------------------------
+        // 璁剧疆璇锋眰杩斿洖鐨勭瓑寰呮椂闂�
+        httpClient.setTimeOut(5);
+
+        // 璁剧疆ca璇佷功
+        // httpClient.setCaInfo(new File(CA_PATH));
+
+        // 璁剧疆涓汉(鍟嗘埛)璇佷功
+        // httpClient.setCertInfo(new File(CERT_PATH), CERT_PWD);
+
+        // 璁剧疆鍙戦�佺被鍨婸OST
+        httpClient.setMethod("POST");
+
+        // 璁剧疆璇锋眰鍐呭(鐢熸垚sign)
+        String requestUrl = reqHandler.getRequestURL();// 缁勬嫾https://www.baidu.com?a=x&b=xx
+
+        httpClient.setReqContent(requestUrl);// https://www.baidu.com?a=x&b=xx
+        String rescontent = "null";
+
+        httpClient.setRequestHandler(reqHandler);// 鎶婂鐞嗗璞★紝鍍忔槸鍙傛暟鍚勭涓滆タ閮借缃繘鍘绘柟渚胯幏鍙�(quan)
+
+        // 杩斿洖鍑哄幓鐨勫璞�(鐘舵�侊紝閿欒鍘熷洜锛岃鎿嶄綔鐩稿叧淇℃伅(鍙傛暟,杩斿洖鍊�))
+        JSONObject returnObj = new JSONObject();
+
+        // 鍚庡彴璋冪敤
+        if (httpClient.call()) {
+            System.out.println("缁熶竴涓嬪崟,鎴愬姛cll浜�::");
+
+            // 璁剧疆缁撴灉鍙傛暟
+            rescontent = httpClient.getResContent();
+            System.out.println("缁熶竴涓嬪崟杩斿洖缁撴灉:" + rescontent);
+            resHandler.setContent(rescontent);// 瑙f瀽xml
+            resHandler.setKey(key);
+
+            // 鑾峰彇杩斿洖鍙傛暟
+            String return_code = resHandler.getParameter("return_code");
+            String return_msg = resHandler.getParameter("return_msg");
+
+            // 鍒ゆ柇绛惧悕鍙婄粨鏋�
+            if (resHandler.isTenpaySign() && "SUCCESS".equals(return_code)) {
+                String prepay_id = resHandler.getParameter("prepay_id");// 棰勬敮浠樹氦鏄撲細璇濇爣璇�
+                String code_url = resHandler.getParameter("code_url");// 浜岀淮鐮侀摼鎺�
+
+                String result_code = resHandler.getParameter("result_code");// 涓氬姟缁撴灉
+                String appid = resHandler.getParameter("appid");// 鍏紬璐﹀彿ID
+                String mch_id = resHandler.getParameter("mch_id");// 鍟嗘埛鍙�
+                String nonce_str = resHandler.getParameter("nonce_str");// 闅忔満鐮�
+                String sign = resHandler.getParameter("sign");// 绛惧悕
+
+                if (result_code.equals("SUCCESS")) {
+                    returnObj.put("status", "suc");
+                    returnObj.put("sign", sign);
+                    returnObj.put("nonce_str", nonce_str);
+                    returnObj.put("mch_id", mch_id);
+                    returnObj.put("appid", appid);
+                    returnObj.put("prepay_id", prepay_id);
+                    returnObj.put("code_url", code_url);
+                    returnObj.put("out_trade_no", out_trade_no);
+                } else {
+                    String errMsg = "[ERROR]result_code:" + resHandler.getParameter("result_code") + " err_code:"
+                            + resHandler.getParameter("err_code") + "err_code_des:"
+                            + resHandler.getParameter("err_code_des");
+
+                    // 閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫��
+                    returnObj.put("status", "ERROR-C");
+                    returnObj.put("errMsg", errMsg);
+                }
+            } else {
+                String errMsg = "return_code:" + return_code + "err_code:" + resHandler.getParameter("err_code")
+                        + " return_msg:" + return_msg;
+                // 閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫��
+                returnObj.put("status", "ERROR-B");
+                returnObj.put("errMsg", errMsg);
+            }
+        } else {
+            // 鏈夊彲鑳藉洜涓虹綉缁滃師鍥狅紝璇锋眰宸茬粡澶勭悊锛屼絾鏈敹鍒板簲绛斻��
+            returnObj.put("status", "ERROR-A");
+            returnObj.put("errMsg", httpClient.getResponseCode() + ":" + httpClient.getErrInfo());
+        }
+
+        // 鑾峰彇debug淇℃伅,寤鸿鎶婅姹傘�佸簲绛斿唴瀹广�乨ebug淇℃伅锛岄�氫俊杩斿洖鐮佸啓鍏ユ棩蹇楋紝鏂逛究瀹氫綅闂
+        String detail = "http res:" + httpClient.getResponseCode() + "," + httpClient.getErrInfo() + ";" + "req url:"
+                + requestUrl + ";" + ";" + "req debug:" + reqHandler.getDebugInfo() + ";" + "res content:" + rescontent
+                + ";" + "res debug:" + resHandler.getDebugInfo() + ";";
+
+        returnObj.put("detail", detail);
+
+
+        return returnObj;
+    }
+
+    /**澶勭悊淇℃伅
+     */
+    public static JSONObject paymentData(JSONObject payObj,String key){
+        JSONObject wxObj = new JSONObject();
+        /**缁熶竴涓嬪崟*/
+        String payStatus = payObj.getString("status");
+        if (payStatus.equals("suc")) {
+            // JSONObject payObj = po.getJSONObject("inf");
+            String appId = payObj.getString("appid");
+            String nonceStr = payObj.getString("nonce_str");
+            String prepay_id = payObj.getString("prepay_id");
+            // JSAPI璋冪敤鏀粯杩斿洖鐨勬暟鎹�
+            String timeStamp = SimpleTool.getTenTime(new Date()).toString();
+            String signType = "MD5";
+            String packagef = "prepay_id=" + prepay_id;
+            RequestHandler reqHandler = new RequestHandler(null, null);
+            reqHandler.setParameter("appId", appId);
+            reqHandler.setParameter("nonceStr", nonceStr);
+            reqHandler.setParameter("timeStamp", timeStamp);
+            reqHandler.setParameter("package", packagef);
+            reqHandler.setParameter("signType", signType);
+            reqHandler.setKey(key);
+            String paySign = reqHandler.createSign();// 鐢熸垚绛惧悕
+            wxObj.put("orderNo", payObj.getString("out_trade_no"));
+            wxObj.put("paySign", paySign);
+            wxObj.put("appId", appId);
+            wxObj.put("nonceStr", nonceStr);
+            wxObj.put("package", packagef);
+            wxObj.put("timeStamp", timeStamp);
+        } else {
+            throw new RuntimeException(payObj.toString());
+        }
+        return wxObj;
+    }
+
+    /**
+     * 閫�娆�
+     * @param appId 灏忕▼搴�/鍏紬鍙� appId
+     * @param partner 鍟嗘埛鍙�
+     * @param key 鍟嗘埛鍙风閽�
+     * @param certPath 涓汉鍟嗘埛璇佷功
+     * @param out_trade_no 鍟嗘埛璁㈠崟鍙�
+     * @param transaction_id 璐粯閫氳鍗曞彿锛堝井淇¤鍗曞彿锛�
+     * @param out_refund_no 鍟嗘埛閫�鍗曞彿
+     * @param total_fee 璁㈠崟鎬婚(鍗曚綅:鍒�)
+     * @param refund_fee 閫�娆鹃噾棰�(鍗曚綅:鍒�)
+     * @return JSON status="SUCCESS"(鎴愬姛) (鐘舵�侊紝閿欒鍘熷洜锛岃鎿嶄綔鐩稿叧淇℃伅(鍙傛暟,杩斿洖鍊�))
+     */
+    public static JSONObject refund(String appId,String partner,String key,String certPath,String out_trade_no, String transaction_id, String out_refund_no, String total_fee,
+    		String refund_fee) {
+ 	    try{  
+             KeyStore keyStore = KeyStore.getInstance("PKCS12");
+             FileInputStream instream = new FileInputStream(new File(certPath));
+             try {  
+                 keyStore.load(instream,partner.toCharArray());
+             }finally {  
+                 instream.close();  
+             }  
+             // Trust own CA and all self-signed certs  
+             SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore,partner.toCharArray()).build();
+             // Allow TLSv1 protocol only  
+             SSLConnectionSocketFactory sslsf;
+            sslsf = new SSLConnectionSocketFactory(
+                    sslcontext, new String[] { "TLSv1" }, null,
+                    SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+            CloseableHttpClient httpclient = HttpClients.custom()
+                     .setSSLSocketFactory(sslsf).build();  
+             HttpPost httppost = new HttpPost(REFUND_URL);
+             String xml = wxPayRefundData(appId, partner, key, out_trade_no, transaction_id, out_refund_no, total_fee, refund_fee);
+             try {
+                 StringEntity se = new StringEntity(xml);
+                 httppost.setEntity(se);  
+
+                 CloseableHttpResponse responseEntry = httpclient.execute(httppost);
+                 try {  
+                     HttpEntity entity = responseEntry.getEntity();
+                     if (entity != null) {
+
+                         SAXReader saxReader = new SAXReader();
+                         Document document = saxReader.read(entity.getContent());
+                         Element rootElt = document.getRootElement();
+                         String returnCode = rootElt.elementText("return_code");
+                         JSONObject result = new JSONObject();
+
+                         if(returnCode.equals("SUCCESS")){
+                             String resultCode = rootElt.elementText("result_code");
+                             if(resultCode.equals("SUCCESS")) {
+                                 result.put("weixinPayUrl", rootElt.elementText("code_url"));
+                                 result.put("prepayId", rootElt.elementText("prepay_id"));
+                                 result.put("msg", "success");
+
+                                 String refund_id = rootElt.elementText("refund_id");//寰俊閫�娆惧崟鍙�
+                                 String r_out_refund_no = rootElt.elementText("out_refund_no");
+                                 String errMsg = "鍟嗘埛鍙�" + r_out_refund_no + "鐨勯��娆炬祦姘村彿鏄細" + refund_id;
+                                 result.put("status", "SUCCESS");
+                                 result.put("errMsg", errMsg);
+                                 result.put("refund_id", refund_id);
+                             }else{
+                                 String errMsg = "[ERROR]result_code:" + rootElt.elementText("result_code")+
+                                         " err_code:" + rootElt.elementText("err_code");
+
+                                 //閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫��
+                                 result.put("errMsg", errMsg);
+                                 result.put("status","false");
+                                 result.put("msg",rootElt.elementText("err_code_des"));
+                             }
+                         }else{  
+                         	String errMsg = "[ERROR]return_code:" + rootElt.elementText("return_code");
+         					
+         					//閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫��
+                         	result.put("errMsg", errMsg);
+                         	result.put("status","false");
+                         	result.put("msg",rootElt.elementText("return_msg"));
+                         }  
+                         return result;  
+                     }  
+                     EntityUtils.consume(entity);
+                 }  
+                 finally {  
+                     responseEntry.close();  
+                 }  
+             }  
+             finally {  
+                 httpclient.close();  
+             }  
+             return null;  
+         }catch(Exception e){  
+             e.printStackTrace();  
+             JSONObject result = new JSONObject();  
+             result.put("status","error");  
+             result.put("msg",e.getMessage());  
+             return result;  
+         }  
+    }
+
+    /** 灏佽鍙傛暟鏁版嵁
+     * @param appId 灏忕▼搴�/鍏紬鍙� appId
+     * @param partner 鍟嗘埛鍙�
+     * @param key 鍟嗘埛鍙风閽�
+     * @param out_trade_no 鍟嗘埛璁㈠崟鍙�
+     * @param transaction_id 璐粯閫氳鍗曞彿锛堝井淇¤鍗曞彿锛�
+     * @param out_refund_no 鍟嗘埛閫�鍗曞彿
+     * @param total_fee 璁㈠崟鎬婚(鍗曚綅:鍒�)
+     * @param refund_fee 閫�娆鹃噾棰�(鍗曚綅:鍒�)
+     * @return
+     */
+    public static String wxPayRefundData(String appId,String partner,String key,String out_trade_no, String transaction_id,String out_refund_no,String total_fee,String refund_fee) {
+        StringBuffer xml = new StringBuffer();
+        String data = null;
+        try {
+            String nonceStr = SimpleTool.getUUIDName().substring(0,30);
+            xml.append("</xml>");
+            SortedMap<String,String> parameters = new TreeMap<String,String>();
+            parameters.put("appid",appId);
+            parameters.put("mch_id",partner);
+            parameters.put("nonce_str", nonceStr);
+            if(!StringUtils.isEmpty(out_trade_no)) {
+                parameters.put("out_trade_no", out_trade_no);
+            }
+            if(!StringUtils.isEmpty(transaction_id)) {
+                parameters.put("transaction_id", transaction_id);
+            }
+            parameters.put("out_refund_no", out_refund_no);
+            parameters.put("fee_type", "CNY");
+            parameters.put("total_fee", total_fee);//鎬婚噾棰�
+            parameters.put("refund_fee", refund_fee);//閫�娆鹃噾棰�
+            parameters.put("op_user_id",partner);
+            parameters.put("sign", createSign(parameters,key));
+            
+            data =SortedMaptoXml(parameters);
+        } catch (Exception e) {
+            System.err.println(e.getMessage());
+            return null;
+        }
+        return data;
+    }
+    
+    /**
+     * 鍒涘缓md5鎽樿,瑙勫垯鏄�:鎸夊弬鏁板悕绉癮-z鎺掑簭,閬囧埌绌哄�肩殑鍙傛暟涓嶅弬鍔犵鍚嶃��
+     */
+    public static String createSign(SortedMap<String, String> packageParams, String AppKey) {
+        StringBuffer sb;
+        sb = new StringBuffer();
+        Set es = packageParams.entrySet();
+        Iterator it = es.iterator();
+        while (it.hasNext()) {
+            Map.Entry entry = (Map.Entry) it.next();
+            String k = (String) entry.getKey();
+            String v = (String) entry.getValue();
+            if (null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {
+                sb.append(k + "=" + v + "&");
+            }
+        }
+        sb.append("key=" + AppKey);
+        String sign = MD5Util.MD5Encode(sb.toString(), "UTF-8").toUpperCase();
+        return sign;
+    }
+    
+    /**
+     * @Author: HONGLINCHEN
+     * @Description:璇锋眰鍊艰浆鎹负xml鏍煎紡 SortedMap杞瑇ml
+     * @param params
+     * @Date: 2017-9-7 17:18
+     */
+    private static String SortedMaptoXml(SortedMap<String,String> params) {
+        StringBuilder sb = new StringBuilder();
+        Set es = params.entrySet();
+        Iterator it = es.iterator();
+        sb.append("<xml>\n");
+        while(it.hasNext()) {
+            Map.Entry entry = (Map.Entry)it.next();
+            String k = (String)entry.getKey();
+            Object v = entry.getValue();
+            sb.append("<"+k+">");
+            sb.append(v);
+            sb.append("</"+k+">\n");
+        }
+        sb.append("</xml>");
+        return sb.toString();
+    }
+}

--
Gitblit v1.8.0