Commit e2bc25cd authored by hezhen's avatar hezhen

添加微信支付

parent a5e1f87f
...@@ -29,5 +29,34 @@ public class SystemConfig { ...@@ -29,5 +29,34 @@ public class SystemConfig {
public static String getCongif(String key) { public static String getCongif(String key) {
return SystemProperty.getConfig(key); return SystemProperty.getConfig(key);
} }
// 微信公众号的配置
public static final String WINXIN_AppID = SystemProperty.getConfig("WINXIN_AppID");
public static final String WINXIN_AppSecret = SystemProperty.getConfig("WINXIN_AppSecret");
public static final String WINXIN_PARTNER_KEY = SystemProperty.getConfig("WINXIN_PARTNER_KEY");
public static final String WINXIN_PARTNER = SystemProperty.getConfig("WINXIN_PARTNER");
// 移动端app微信支付配置参数
/**
* appStore配置
*/
// 微信开发平台应用id(OK)
public static String APP_ID = SystemProperty.getConfig("APP_ID");
// 财付通商户号(OK)
public static String APP_PARTNER = SystemProperty.getConfig("APP_PARTNER");
// 商户号对应的密钥//(OK)
public static String APP_PARTNER_KEY = SystemProperty.getConfig("APP_PARTNER_KEY");
public static String APP_TRADE_TYPE = SystemProperty.getConfig("APP_TRADE_TYPE");
/**
* (IOS)企业版配置
*/
public static String APP_ID_IOS = SystemProperty.getConfig("APP_ID_IOS");
// 微信开发平台应用id(OK)
public static String APP_PARTNER_IOS = SystemProperty.getConfig("APP_PARTNER_IOS");
// 财付通商户号(OK)
public static String APP_PARTNER_KEY_IOS = SystemProperty.getConfig("APP_PARTNER_KEY_IOS");
// 商户号对应的密钥//(OK)
public static String APP_TRADE_TYPE_IOS = SystemProperty.getConfig("APP_TRADE_TYPE");
// 平台所有微信的回调地址的域名
public static final String weixinHost = SystemProperty.getConfig("weixinHost");
} }
...@@ -17,3 +17,20 @@ ACCESSKEYID=LTAIlXrgxOBAj2Ny ...@@ -17,3 +17,20 @@ ACCESSKEYID=LTAIlXrgxOBAj2Ny
ACCESSKEYSECRET=zo8OkOCF4iygqOjYYoxRKfVRxDvgTI ACCESSKEYSECRET=zo8OkOCF4iygqOjYYoxRKfVRxDvgTI
TEMPLATECODE=SMS_166480010 TEMPLATECODE=SMS_166480010
SIGNNAME=升云 SIGNNAME=升云
#微信支付配置
WINXIN_AppID=wxcc2c9b7c87439a6d
WINXIN_AppSecret=279796e8c2963c8a5ddc8270ef642b29
WINXIN_PARTNER_KEY=CNITR89201000CNITR89201000FUWUSH
WINXIN_PARTNER=1512136241
#ios
APP_ID_IOS=wx3f51779d49171d63
APP_PARTNER_IOS=1492557632
APP_PARTNER_KEY_IOS=89201002892010008920100quanzinet
APP_TRADE_TYPE_IOS=APP
#andoir
APP_ID=wxa9805823769294b6
APP_PARTNER=1327473801
APP_PARTNER_KEY=cnitr89201000QZNWcnitr89201000QZ
APP_TRADE_TYPE=APP
#支付回调
weixinHost=xxfcmgmt.upyuns.com
...@@ -10,7 +10,7 @@ spring: ...@@ -10,7 +10,7 @@ spring:
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.jdbc.Driver driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://10.5.52.3:3306/vehicle?useUnicode=true&characterEncoding=UTF-8 url: jdbc:mysql://10.5.52.3:3306/xxfc_third_platform?useUnicode=true&characterEncoding=UTF-8
username: root username: root
password: sslcloud123*() password: sslcloud123*()
jackson: jackson:
......
#代码生成器,配置信息 #代码生成器,配置信息
#包名 #包名
package=com.xxfc.platform.vehicle package=com.xxfc.platform.universal
#作者 #作者
author=zjw author=zjw
#Email #Email
......
...@@ -11,5 +11,37 @@ ...@@ -11,5 +11,37 @@
<groupId>com.xxfc.platform</groupId> <groupId>com.xxfc.platform</groupId>
<artifactId>xx-universal-api</artifactId> <artifactId>xx-universal-api</artifactId>
<dependencies>
<!-- xstream XML工具-->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.5</version>
</dependency>
<!-- XML解析包 -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<!-- 微信支付需要的jar -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1.3</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
</dependency>
</dependencies>
</project> </project>
\ No newline at end of file
package com.xxfc.platform.universal.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 订单支付
*
* @author zjw
* @email nishijjo@qq.com
* @date 2019-05-28 16:17:42
*/
@Data
@Table(name = "order_pay")
public class OrderPay implements Serializable {
private static final long serialVersionUID = 1L;
//
@Id
@GeneratedValue(generator = "JDBC")
@ApiModelProperty("")
private Integer id;
//支付订单号
@Column(name = "trade_no")
@ApiModelProperty(value = "支付订单号")
private String tradeNo;
//订单号
@Column(name = "order_no")
@ApiModelProperty(value = "订单号")
private String orderNo;
//用户id
@Column(name = "user_id")
@ApiModelProperty(value = "用户id")
private Integer userId;
//1:微信公众号支付 2.支付宝即时到账,3,银联
@Column(name = "pay_way")
@ApiModelProperty(value = "1:微信公众号支付 2.支付宝即时到账,3,银联")
private Integer payWay;
//渠道:1-租车;2-旅游
@Column(name = "channel")
@ApiModelProperty(value = "渠道:1-租车;2-旅游")
private Integer channel;
//来源:1-app;2-小程序
@Column(name = "type")
@ApiModelProperty(value = "来源:1-app;2-小程序")
private Integer type;
//买家IP地址
@Column(name = "buyer_ip")
@ApiModelProperty(value = "买家IP地址")
private String buyerIp;
//商品标题
@Column(name = "subject")
@ApiModelProperty(value = "商品标题")
private String subject;
//商品描述信息
@Column(name = "body")
@ApiModelProperty(value = "商品描述信息")
private String body;
//回调地址
@Column(name = "notify_url")
@ApiModelProperty(value = "回调地址")
private String notifyUrl;
//支付状态0:未支付 1:已支付
@Column(name = "status")
@ApiModelProperty(value = "支付状态0:未支付 1:已支付")
private Integer status;
//支付金额
@Column(name = "amount")
@ApiModelProperty(value = "支付金额")
private Integer amount;
//是否删除
@Column(name = "is_del")
@ApiModelProperty(value = "是否删除")
private Integer isDel;
//支付接口返回的流水号
@Column(name = "serial_number")
@ApiModelProperty(value = "支付接口返回的流水号")
private String serialNumber;
//买家第三方付款账号
@Column(name = "buyer_account")
@ApiModelProperty(value = "买家第三方付款账号")
private String buyerAccount;
//卖家第三方收款账号
@Column(name = "seller_account")
@ApiModelProperty(value = "卖家第三方收款账号")
private String sellerAccount;
//创建时间
@Column(name = "crt_time")
@ApiModelProperty(value = "创建时间", hidden = true )
private Long crtTime;
//更新时间
@Column(name = "upd_time")
@ApiModelProperty(value = "更新时间", hidden = true )
private Long updTime;
//支付完成时间
@Column(name = "finish_time")
@ApiModelProperty(value = "支付完成时间")
private Long finishTime;
}
package com.xxfc.platform.universal.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 订单支付退款表
*
* @author zjw
* @email nishijjo@qq.com
* @date 2019-05-28 16:17:42
*/
@Data
@Table(name = "order_refund")
public class OrderRefund implements Serializable {
private static final long serialVersionUID = 1L;
//
@Id
@GeneratedValue(generator = "JDBC")
@ApiModelProperty("")
private Integer id;
//退款订单号
@Column(name = "refund_trade_no")
@ApiModelProperty(value = "退款订单号")
private String refundTradeNo;
//订单号
@Column(name = "order_no")
@ApiModelProperty(value = "订单号")
private String orderNo;
//用户id
@Column(name = "user_id")
@ApiModelProperty(value = "用户id")
private Integer userId;
//0-订单生成,1-退款中,2-退款成功,3-退款失败
@Column(name = "status")
@ApiModelProperty(value = "0-订单生成,1-退款中,2-退款成功,3-退款失败")
private Integer status;
//支付金额
@Column(name = "amount")
@ApiModelProperty(value = "支付金额")
private Integer amount;
//退款金额
@Column(name = "refund_amount")
@ApiModelProperty(value = "退款金额")
private Integer refundAmount;
//是否删除
@Column(name = "is_del")
@ApiModelProperty(value = "是否删除")
private Integer isDel;
//商户退款单号
@Column(name = "out_refund_no")
@ApiModelProperty(value = "商户退款单号")
private String outRefundNo;
//支付接口返回的流水号
@Column(name = "serial_number")
@ApiModelProperty(value = "支付接口返回的流水号")
private String serialNumber;
//创建时间
@Column(name = "crt_time")
@ApiModelProperty(value = "创建时间", hidden = true )
private Long crtTime;
//更新时间
@Column(name = "upd_time")
@ApiModelProperty(value = "更新时间", hidden = true )
private Long updTime;
//退款完成时间
@Column(name = "finish_time")
@ApiModelProperty(value = "退款完成时间")
private Long finishTime;
}
package com.xxfc.platform.universal.feign; package com.xxfc.platform.universal.feign;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.xxfc.platform.universal.vo.OrderPayVo;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -20,4 +22,7 @@ public interface ThirdFeign { ...@@ -20,4 +22,7 @@ public interface ThirdFeign {
public JSONObject send(@RequestParam(value = "phone") String phone); public JSONObject send(@RequestParam(value = "phone") String phone);
@RequestMapping(value = "/file/app/unauth/uploadFiles", method = RequestMethod.POST) @RequestMapping(value = "/file/app/unauth/uploadFiles", method = RequestMethod.POST)
public JSONObject uploadFiles(@RequestParam("files") MultipartFile[] files); public JSONObject uploadFiles(@RequestParam("files") MultipartFile[] files);
@RequestMapping(value = "/pay/app/wx", method = RequestMethod.POST)
public JSONObject wx(@RequestBody OrderPayVo orderPayVo);
} }
package com.xxfc.platform.universal.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**
* 下单
*
* @author zjw
* @email nishijjo@qq.com
* @date 2019-05-28 16:17:42
*/
@Data
public class OrderPayVo{
//订单号
private String orderNo;
//用户id
private Integer userId;
//1:微信公众号支付 2.支付宝即时到账,3,银联
private Integer payWay;
//渠道:1-租车;2-旅游
private Integer channel;
//来源:1-app;2-小程序
private Integer type;
//买家IP地址
private String buyerIp;
//商品标题
private String subject;
//商品描述信息
private String body;
//回调地址
private String notifyUrl;
//支付金额
private Integer amount;
//买家第三方付款账号
private String buyerAccount;
}
package com.xxfc.platform.universal.weixin.util;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
/**
* Http客户端工具类<br/>
* 这是内部调用类,请不要在外部调用。
* @author miklchen
*
*/
public class HttpClientUtil {
public static final String SunX509 = "SunX509";
public static final String JKS = "JKS";
public static final String PKCS12 = "PKCS12";
public static final String TLS = "TLS";
/**
* get HttpURLConnection
* @param strUrl url地址
* @return HttpURLConnection
* @throws IOException
*/
public static HttpURLConnection getHttpURLConnection(String strUrl)
throws IOException {
URL url = new URL(strUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection();
return httpURLConnection;
}
/**
* get HttpsURLConnection
* @param strUrl url地址
* @return HttpsURLConnection
* @throws IOException
*/
public static HttpsURLConnection getHttpsURLConnection(String strUrl)
throws IOException {
URL url = new URL(strUrl);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url
.openConnection();
return httpsURLConnection;
}
/**
* 获取不带查询串的url
* @param strUrl
* @return String
*/
public static String getURL(String strUrl) {
if(null != strUrl) {
int indexOf = strUrl.indexOf("?");
if(-1 != indexOf) {
return strUrl.substring(0, indexOf);
}
return strUrl;
}
return strUrl;
}
/**
* 获取查询串
* @param strUrl
* @return String
*/
public static String getQueryString(String strUrl) {
if(null != strUrl) {
int indexOf = strUrl.indexOf("?");
if(-1 != indexOf) {
return strUrl.substring(indexOf+1, strUrl.length());
}
return "";
}
return strUrl;
}
/**
* 查询字符串转换成Map<br/>
* name1=key1&name2=key2&...
* @param queryString
* @return
*/
public static Map queryString2Map(String queryString) {
if(null == queryString || "".equals(queryString)) {
return null;
}
Map m = new HashMap();
String[] strArray = queryString.split("&");
for(int index = 0; index < strArray.length; index++) {
String pair = strArray[index];
HttpClientUtil.putMapByPair(pair, m);
}
return m;
}
/**
* 把键值添加至Map<br/>
* pair:name=value
* @param pair name=value
* @param m
*/
public static void putMapByPair(String pair, Map m) {
if(null == pair || "".equals(pair)) {
return;
}
int indexOf = pair.indexOf("=");
if(-1 != indexOf) {
String k = pair.substring(0, indexOf);
String v = pair.substring(indexOf+1, pair.length());
if(null != k && !"".equals(k)) {
m.put(k, v);
}
} else {
m.put(pair, "");
}
}
/**
* BufferedReader转换成String<br/>
* 注意:流关闭需要自行处理
* @param reader
* @return String
* @throws IOException
*/
public static String bufferedReader2String(BufferedReader reader) throws IOException {
StringBuffer buf = new StringBuffer();
String line = null;
while( (line = reader.readLine()) != null) {
buf.append(line);
buf.append("\r\n");
}
return buf.toString();
}
/**
* 处理输出<br/>
* 注意:流关闭需要自行处理
* @param out
* @param data
* @param len
* @throws IOException
*/
public static void doOutput(OutputStream out, byte[] data, int len)
throws IOException {
int dataLen = data.length;
int off = 0;
while(off < dataLen) {
if(len >= dataLen) {
out.write(data, off, dataLen);
} else {
out.write(data, off, len);
}
//刷新缓冲区
out.flush();
off += len;
dataLen -= len;
}
}
/**
* 获取SSLContext
* @param trustPasswd
* @param keyPasswd
* @return
* @throws NoSuchAlgorithmException
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
* @throws UnrecoverableKeyException
* @throws KeyManagementException
*/
public static SSLContext getSSLContext(
FileInputStream trustFileInputStream, String trustPasswd,
FileInputStream keyFileInputStream, String keyPasswd)
throws NoSuchAlgorithmException, KeyStoreException,
CertificateException, IOException, UnrecoverableKeyException,
KeyManagementException {
// ca
TrustManagerFactory tmf = TrustManagerFactory.getInstance(HttpClientUtil.SunX509);
KeyStore trustKeyStore = KeyStore.getInstance(HttpClientUtil.JKS);
trustKeyStore.load(trustFileInputStream, HttpClientUtil
.str2CharArray(trustPasswd));
tmf.init(trustKeyStore);
final char[] kp = HttpClientUtil.str2CharArray(keyPasswd);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(HttpClientUtil.SunX509);
KeyStore ks = KeyStore.getInstance(HttpClientUtil.PKCS12);
ks.load(keyFileInputStream, kp);
kmf.init(ks, kp);
SecureRandom rand = new SecureRandom();
SSLContext ctx = SSLContext.getInstance(HttpClientUtil.TLS);
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), rand);
return ctx;
}
/**
* 获取CA证书信息
* @param cafile CA证书文件
* @return Certificate
* @throws CertificateException
* @throws IOException
*/
public static Certificate getCertificate(File cafile)
throws CertificateException, IOException {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
FileInputStream in = new FileInputStream(cafile);
Certificate cert = cf.generateCertificate(in);
in.close();
return cert;
}
/**
* 字符串转换成char数组
* @param str
* @return char[]
*/
public static char[] str2CharArray(String str) {
if(null == str) return null;
return str.toCharArray();
}
/**
* 存储ca证书成JKS格式
* @param cert
* @param alias
* @param password
* @param out
* @throws KeyStoreException
* @throws NoSuchAlgorithmException
* @throws CertificateException
* @throws IOException
*/
public static void storeCACert(Certificate cert, String alias,
String password, OutputStream out) throws KeyStoreException,
NoSuchAlgorithmException, CertificateException, IOException {
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, null);
ks.setCertificateEntry(alias, cert);
// store keystore
ks.store(out, HttpClientUtil.str2CharArray(password));
}
public static InputStream String2Inputstream(String str) {
return new ByteArrayInputStream(str.getBytes());
}
}
package com.xxfc.platform.universal.weixin.util;
import java.security.MessageDigest;
public class MD5Util {
private static String byteArrayToHexString(byte b[]) {
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.length; i++)
resultSb.append(byteToHexString(b[i]));
return resultSb.toString();
}
private static String byteToHexString(byte b) {
int n = b;
if (n < 0)
n += 256;
int d1 = n / 16;
int d2 = n % 16;
return hexDigits[d1] + hexDigits[d2];
}
public static String MD5Encode(String origin, String charsetname) {
String resultString = null;
try {
resultString = new String(origin);
MessageDigest md = MessageDigest.getInstance("MD5");
if (charsetname == null || "".equals(charsetname))
resultString = byteArrayToHexString(md.digest(resultString
.getBytes()));
else
resultString = byteArrayToHexString(md.digest(resultString
.getBytes(charsetname)));
} catch (Exception exception) {
}
return resultString;
}
private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
//Sha1签名
public static String getSha1(String str) {
if (str == null || str.length() == 0) {
return null;
}
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f' };
try {
MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
mdTemp.update(str.getBytes("GBK"));
byte[] md = mdTemp.digest();
int j = md.length;
char buf[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
buf[k++] = hexDigits[byte0 & 0xf];
}
return new String(buf);
} catch (Exception e) {
return null;
}
}
}
package com.xxfc.platform.universal.weixin.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class OrderUtil {
static Date today = new Date();
static int orderIndex = 0;
@SuppressWarnings("deprecation")
private static String getIndex() {
Date n = new Date();
SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String currTime = outFormat.format(n);
if (orderIndex > 0) {
if (n.getYear() == today.getYear() && n.getMonth() == today.getMonth() && n.getDay() == today.getDay()) {
orderIndex += 1;
} else {
today = n;
orderIndex = 1;
}
} else {
today = n;
orderIndex = 1;
}
if (orderIndex > 999999) {
orderIndex = 1;
}
String indexString = String.format("%s%06d", currTime, orderIndex);
return indexString;
}
/**
* 生成订单号
*
* @param preFixString
* @return
*/
public static String GetOrderNumber(String preFixString) {
String orderNumberString = preFixString + getIndex();
return orderNumberString;
}
/**
* 获取时间戳
*
* @return
*/
public static String GetTimestamp() {
return Long.toString(new Date().getTime() / 1000);
}
/**
* 生成随机数
*
* @return
*/
public static String CreateNoncestr() {
Random random = new Random();
return MD5.GetMD5String(String.valueOf(random.nextInt(10000)));
}
}
package com.xxfc.platform.universal.weixin.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
/**
* xml工具类
* @author miklchen
*
*/
@Slf4j
public class XMLUtil {
/**
* 解析xml,返回第一级元素键值对。如果第一级元素有子节点,则此节点的值是子节点的xml数据。
* @param strxml
* @return
* @throws JDOMException
* @throws IOException
*/
public static Map doXMLParse(String strxml) throws JDOMException, IOException {
if(null == strxml || "".equals(strxml)) {
return null;
}
Map m = new HashMap();
InputStream in = HttpClientUtil.String2Inputstream(strxml);
// 2018-12-19注释原代码
// SAXBuilder builder = new SAXBuilder();
// Document doc = builder.build(in);
// Element root = doc.getRootElement();
// 2018-12-19,添加XXE漏洞代码(下6行代码)
SAXBuilder builder = new SAXBuilder();
builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl",true);
builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
builder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
Document doc = builder.build(in);
Element root = doc.getRootElement();
log.error("==== XMLUtil.doXMLParse ===== ");
List list = root.getChildren();
Iterator it = list.iterator();
while(it.hasNext()) {
Element e = (Element) it.next();
String k = e.getName();
String v = "";
List children = e.getChildren();
if(children.isEmpty()) {
v = e.getTextNormalize();
} else {
v = XMLUtil.getChildrenText(children);
}
m.put(k, v);
}
//关闭流
in.close();
return m;
}
/**
* 获取子结点的xml
* @param children
* @return String
*/
public static String getChildrenText(List children) {
StringBuffer sb = new StringBuffer();
if(!children.isEmpty()) {
Iterator it = children.iterator();
while(it.hasNext()) {
Element e = (Element) it.next();
String name = e.getName();
String value = e.getTextNormalize();
List list = e.getChildren();
sb.append("<" + name + ">");
if(!list.isEmpty()) {
sb.append(XMLUtil.getChildrenText(list));
}
sb.append(value);
sb.append("</" + name + ">");
}
}
return sb.toString();
}
/**
* 获取xml编码字符集
* @param strxml
* @return
* @throws IOException
* @throws JDOMException
*/
public static String getXMLEncoding(String strxml) throws JDOMException, IOException {
InputStream in = HttpClientUtil.String2Inputstream(strxml);
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(in);
in.close();
return (String)doc.getProperty("encoding");
}
}
package com.xxfc.platform.universal.biz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import com.xxfc.platform.universal.vo.OrderPayVo;
import com.xxfc.platform.universal.weixin.api.WXPay;
import com.xxfc.platform.universal.weixin.util.OrderUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.xxfc.platform.universal.entity.OrderPay;
import com.xxfc.platform.universal.mapper.OrderPayMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
/**
* 订单支付
*
* @author zjw
* @email nishijjo@qq.com
* @date 2019-05-28 16:17:42
*/
@Service
@Slf4j
public class OrderPayBiz extends BaseBiz<OrderPayMapper,OrderPay> {
public JSONObject preparepay( OrderPayVo orderPayVo) {
if(null == orderPayVo) {
log.error("-----参数为空-----------");
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
if(orderPayVo.getAmount()==null||orderPayVo.getAmount()==0) {
log.error("-----金额不为为0-----------");
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "金额不为为0");
}
if(StringUtils.isBlank(orderPayVo.getOrderNo())) {
log.error("-----订单不能为空-----------");
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "订单不能为空");
}
String trade_no = OrderUtil.GetOrderNumber("");
String order_no=orderPayVo.getOrderNo();
Integer amount=orderPayVo.getAmount();
log.error("---下单---order_no====="+order_no+"--支付订单号--trade_no===="+trade_no+"--金额---amount===="+amount);
//报名费回调路径
String jsParam = WXPay.apppay(amount+"",orderPayVo.getBody(),"https://"+ SystemConfig.weixinHost+"/icircle/activity/notice.do" ,order_no,orderPayVo.getBuyerIp(),0);
log.info("报名费回调路径jsParam:"+jsParam);
if(!StringUtils.isBlank(jsParam))
{
try {
OrderPay orderPay= new OrderPay();
BeanUtils.copyProperties(orderPay,orderPayVo);
orderPay.setTradeNo(trade_no);
orderPay.setSellerAccount(SystemConfig.APP_PARTNER);
insertSelective(orderPay);
log.error("---下单---order_no====="+order_no+"----成功");
} catch (Exception e) {
e.printStackTrace();
log.error("---下单---order_no====="+order_no+"----异常---msg==="+ e.getMessage());
return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
}
JSONObject temp = JSON.parseObject(jsParam);
return JsonResultUtil.createSuccessResultWithObj(temp);
}else{
return JsonResultUtil.createDefaultFail();
}
}
//支付回调
public void notice(String orderNo,String serialNumber){
log.error("---支付回调---order_no====="+orderNo+"----开始处理");
Example example =new Example(OrderPay.class);
example.createCriteria().andEqualTo("order_no",orderNo).andEqualTo("is_del",0).andEqualTo("status",0);
List<OrderPay> list=mapper.selectByExample(example);
if(list.size()==0){
log.error("---支付回调---order_no====="+orderNo+"----订单不存在或已处理");
return;
}
example.clear();
example.createCriteria().andEqualTo("order_no",orderNo);
OrderPay orderPay=new OrderPay();
orderPay.setFinishTime(System.currentTimeMillis());
orderPay.setStatus(1);
orderPay.setSerialNumber(serialNumber);
mapper.updateByExampleSelective(orderPay,example);
}
}
\ No newline at end of file
package com.xxfc.platform.universal.biz;
import org.springframework.stereotype.Service;
import com.xxfc.platform.universal.entity.OrderRefund;
import com.xxfc.platform.universal.mapper.OrderRefundMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
/**
* 订单支付退款表
*
* @author zjw
* @email nishijjo@qq.com
* @date 2019-05-28 16:17:42
*/
@Service
public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> {
}
\ No newline at end of file
package com.xxfc.platform.universal.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.xxfc.platform.universal.biz.OrderPayBiz;
import com.xxfc.platform.universal.entity.OrderPay;
import com.xxfc.platform.universal.vo.OrderPayVo;
import com.xxfc.platform.universal.weixin.util.XMLUtil;
import org.jdom.JDOMException;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
@RestController
@RequestMapping("pay")
public class OrderPayController extends BaseController<OrderPayBiz,OrderPay> {
/**
* APP支付
*
* @param orderPayVo
* @return
* @throws Exception
*/
@RequestMapping(value = "/app/wx", method = RequestMethod.POST) //匹配的是href中的download请求
public JSONObject wx(@RequestBody OrderPayVo orderPayVo) {
return baseBiz.preparepay(orderPayVo);
}
/**
* 支付回调
*
* @param request
* @param response
* @throws IOException
*/
@RequestMapping(value = "/app/unauth/notify", method = RequestMethod.POST) //匹配的是href中的download请求
@IgnoreUserToken
public void notice(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
InputStream inStream = request.getInputStream();
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outSteam.write(buffer, 0, len);
}
outSteam.close();
inStream.close();
String result = new String(outSteam.toByteArray(), "utf-8");
Map<String, String> map = null;
try {
map = XMLUtil.doXMLParse(result);
} catch (JDOMException e) {
e.printStackTrace();
}
if ("SUCCESS".equals(map.get("return_code")) && "SUCCESS".equals(map.get("result_code"))) {
try {
String orderno = map.get("out_trade_no");
String serialNumber = map.get("transaction_id");
baseBiz.notice(orderno, serialNumber);
} catch (Exception e) {
e.printStackTrace();
}
out.print("<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[]]></return_msg></xml>");
} else
out.print("<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[]]></return_msg></xml>");
}
}
\ No newline at end of file
package com.xxfc.platform.universal.controller;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.xxfc.platform.universal.biz.OrderRefundBiz;
import com.xxfc.platform.universal.entity.OrderRefund;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("orderRefund")
public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRefund> {
}
\ No newline at end of file
package com.xxfc.platform.universal.mapper;
import com.xxfc.platform.universal.entity.OrderPay;
import tk.mybatis.mapper.common.Mapper;
/**
* 订单支付
*
* @author zjw
* @email nishijjo@qq.com
* @date 2019-05-28 16:17:42
*/
public interface OrderPayMapper extends Mapper<OrderPay> {
}
package com.xxfc.platform.universal.mapper;
import com.xxfc.platform.universal.entity.OrderRefund;
import tk.mybatis.mapper.common.Mapper;
/**
* 订单支付退款表
*
* @author zjw
* @email nishijjo@qq.com
* @date 2019-05-28 16:17:42
*/
public interface OrderRefundMapper extends Mapper<OrderRefund> {
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxfc.platform.universal.mapper.OrderPayMapper">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.xxfc.platform.universal.entity.OrderPay" id="orderPayMap">
<result property="id" column="id"/>
<result property="tradeNo" column="trade_no"/>
<result property="orderNo" column="order_no"/>
<result property="userId" column="user_id"/>
<result property="payWay" column="pay_way"/>
<result property="channel" column="channel"/>
<result property="type" column="type"/>
<result property="buyerIp" column="buyer_ip"/>
<result property="subject" column="subject"/>
<result property="body" column="body"/>
<result property="notifyUrl" column="notify_url"/>
<result property="status" column="status"/>
<result property="amount" column="amount"/>
<result property="isDel" column="is_del"/>
<result property="serialNumber" column="serial_number"/>
<result property="buyerAccount" column="buyer_account"/>
<result property="sellerAccount" column="seller_account"/>
<result property="crtTime" column="crt_time"/>
<result property="updTime" column="upd_time"/>
<result property="finishTime" column="finish_time"/>
</resultMap>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxfc.platform.universal.mapper.OrderRefundMapper">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.xxfc.platform.universal.entity.OrderRefund" id="orderRefundMap">
<result property="id" column="id"/>
<result property="refundTradeNo" column="refund_trade_no"/>
<result property="orderNo" column="order_no"/>
<result property="userId" column="user_id"/>
<result property="status" column="status"/>
<result property="amount" column="amount"/>
<result property="refundAmount" column="refund_amount"/>
<result property="isDel" column="is_del"/>
<result property="outRefundNo" column="out_refund_no"/>
<result property="serialNumber" column="serial_number"/>
<result property="crtTime" column="crt_time"/>
<result property="updTime" column="upd_time"/>
<result property="finishTime" column="finish_time"/>
</resultMap>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment