Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
youjj
cloud-platform
Commits
743ae98a
Commit
743ae98a
authored
Sep 29, 2019
by
hezhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
123
parent
76b6ce77
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
767 additions
and
10 deletions
+767
-10
HTTPSUtils.java
...in/java/com/xxfc/platform/universal/utils/HTTPSUtils.java
+121
-0
RequestHandler.java
...ava/com/xxfc/platform/universal/utils/RequestHandler.java
+250
-0
WeiXinPayUtil.java
...java/com/xxfc/platform/universal/utils/WeiXinPayUtil.java
+185
-0
WxPrepay.java
...main/java/com/xxfc/platform/universal/utils/WxPrepay.java
+115
-0
WXPay.java
...in/java/com/xxfc/platform/universal/weixin/api/WXPay.java
+93
-9
OrderPayBiz.java
...ain/java/com/xxfc/platform/universal/biz/OrderPayBiz.java
+3
-1
No files found.
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/utils/HTTPSUtils.java
0 → 100644
View file @
743ae98a
package
com
.
xxfc
.
platform
.
universal
.
utils
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.net.ConnectException
;
import
java.net.URL
;
import
java.security.KeyStore
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLSocketFactory
;
import
javax.net.ssl.TrustManager
;
import
com.github.wxiaoqi.security.common.util.MyX509TrustManager
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
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.conn.ssl.SSLContexts
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
/**
* @Author vitoHuang
* @Time 2015年8月14日
* @Mark HTTPS请求工具
*/
@Slf4j
public
class
HTTPSUtils
{
/**
* HTTPS json 请求
* @param requestUrl 请求地址
* @param requestMethod 请求方式 POST/GET
* @param msg json方式的请求参数
* @return 返回相应的字符串 异常会输出null
*/
public
static
String
httpRequest
(
String
requestUrl
,
String
requestMethod
,
String
msg
){
log
.
error
(
"进入方法httpRequest()httpRequest="
+
requestUrl
);
OutputStream
outputStream
=
null
;
InputStream
inputStream
=
null
;
try
{
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
TrustManager
[]
tm
=
{
new
MyX509TrustManager
()};
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"SSL"
,
"SunJSSE"
);
sslContext
.
init
(
null
,
tm
,
new
java
.
security
.
SecureRandom
());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SSLSocketFactory
ssf
=
sslContext
.
getSocketFactory
();
URL
url
=
new
URL
(
requestUrl
);
HttpsURLConnection
httpUrlConn
=
(
HttpsURLConnection
)
url
.
openConnection
();
httpUrlConn
.
setSSLSocketFactory
(
ssf
);
httpUrlConn
.
setDoOutput
(
true
);
httpUrlConn
.
setDoInput
(
true
);
httpUrlConn
.
setUseCaches
(
false
);
// 设置请求方式(GET/POST)
httpUrlConn
.
setRequestMethod
(
requestMethod
);
if
(
"GET"
.
equalsIgnoreCase
(
requestMethod
))
httpUrlConn
.
connect
();
// 当有数据需要提交时
log
.
error
(
"httpUrlConn="
+
httpUrlConn
);
if
(
null
!=
msg
)
{
outputStream
=
httpUrlConn
.
getOutputStream
();
// 注意编码格式,防止中文乱码
outputStream
.
write
(
msg
.
getBytes
(
"UTF-8"
));
}
// 将返回的输入流转换成字符串
inputStream
=
httpUrlConn
.
getInputStream
();
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
inputStream
,
"UTF-8"
);
log
.
error
(
"inputStreamReader="
+
inputStreamReader
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
inputStreamReader
);
StringBuffer
buffer
=
new
StringBuffer
();
String
str
=
null
;
while
((
str
=
bufferedReader
.
readLine
())
!=
null
)
{
buffer
.
append
(
str
);
}
httpUrlConn
.
disconnect
();
return
buffer
.
toString
();
}
catch
(
ConnectException
ce
)
{
log
.
error
(
"Weixin server connection timed out."
);
}
catch
(
Exception
e
)
{
log
.
error
(
"https request error:"
+
e
.
getMessage
());
}
finally
{
if
(
outputStream
!=
null
)
try
{
outputStream
.
close
();}
catch
(
Exception
e
)
{}
if
(
inputStream
!=
null
)
try
{
inputStream
.
close
();;}
catch
(
Exception
e
)
{}
}
return
null
;
}
/**
* HTTPS json 请求
* @param requestUrl
* @param requestMethod
* @param msg
* @return 对字符串进行封装成JSON
*/
public
static
JSONObject
httpRequestToJSON
(
String
requestUrl
,
String
requestMethod
,
String
msg
){
log
.
error
(
"进入方法httpRequestToJSON-----"
);
String
json
=
httpRequest
(
requestUrl
,
requestMethod
,
msg
);
log
.
error
(
"json-----"
+
json
);
JSONObject
jsonObject
=
null
;
if
(
StringUtils
.
isNotBlank
(
json
))
jsonObject
=
JSON
.
parseObject
(
json
);
return
jsonObject
;
}
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/utils/RequestHandler.java
0 → 100644
View file @
743ae98a
package
com
.
xxfc
.
platform
.
universal
.
utils
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
/*
'微信支付服务器签名支付请求请求类
'============================================================================
'api说明:
'init(app_id, app_secret, partner_key, app_key);
'初始化函数,默认给一些参数赋值,如cmdno,date等。
'setKey(key_)'设置商户密钥
'getLasterrCode(),获取最后错误号
'GetToken();获取Token
'getTokenReal();Token过期后实时获取Token
'createMd5Sign(signParams);生成Md5签名
'genPackage(packageParams);获取package包
'createSHA1Sign(signParams);创建签名SHA1
'sendPrepay(packageParams);提交预支付
'getDebugInfo(),获取debug信息
'============================================================================
'*/
public
class
RequestHandler
{
/** Token获取网关地址地址 */
private
String
tokenUrl
;
/** 预支付网关url地址 */
private
String
gateUrl
;
/** 查询支付通知网关URL */
private
String
notifyUrl
;
/** 商户参数 */
private
String
appid
;
private
String
appkey
;
private
String
partnerkey
;
private
String
appsecret
;
private
String
key
;
/** 请求的参数 */
private
SortedMap
parameters
;
/** Token */
private
String
Token
;
private
String
charset
;
/** debug信息 */
private
String
debugInfo
;
private
String
last_errcode
;
private
HttpServletRequest
request
;
private
HttpServletResponse
response
;
/**
* 初始构造函数。
*
* @return
*/
public
RequestHandler
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
this
.
last_errcode
=
"0"
;
this
.
request
=
request
;
this
.
response
=
response
;
//this.charset = "GBK";
this
.
charset
=
"UTF-8"
;
this
.
parameters
=
new
TreeMap
();
// 验证notify支付订单网关
notifyUrl
=
"https://gw.tenpay.com/gateway/simpleverifynotifyid.xml"
;
}
/**
* 初始化函数。
*/
public
void
init
(
String
app_id
,
String
app_secret
,
String
partner_key
)
{
this
.
last_errcode
=
"0"
;
this
.
Token
=
"token_"
;
this
.
debugInfo
=
""
;
this
.
appid
=
app_id
;
this
.
partnerkey
=
partner_key
;
this
.
appsecret
=
app_secret
;
this
.
key
=
partner_key
;
}
public
void
init
()
{
}
/**
* 获取最后错误号
*/
public
String
getLasterrCode
()
{
return
last_errcode
;
}
/**
*获取入口地址,不包含参数值
*/
public
String
getGateUrl
()
{
return
gateUrl
;
}
/**
* 获取参数值
*
* @param parameter
* 参数名称
* @return String
*/
public
String
getParameter
(
String
parameter
)
{
String
s
=
(
String
)
this
.
parameters
.
get
(
parameter
);
return
(
null
==
s
)
?
""
:
s
;
}
//设置密钥
public
void
setKey
(
String
key
)
{
this
.
partnerkey
=
key
;
}
//设置微信密钥
public
void
setAppKey
(
String
key
){
this
.
appkey
=
key
;
}
// 特殊字符处理
public
String
UrlEncode
(
String
src
)
throws
UnsupportedEncodingException
{
return
URLEncoder
.
encode
(
src
,
this
.
charset
).
replace
(
"+"
,
"%20"
);
}
// 获取package的签名包
public
String
genPackage
(
SortedMap
<
String
,
String
>
packageParams
)
throws
UnsupportedEncodingException
{
String
sign
=
createSign
(
packageParams
);
StringBuffer
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
();
sb
.
append
(
k
+
"="
+
UrlEncode
(
v
)
+
"&"
);
}
// 去掉最后一个&
String
packageValue
=
sb
.
append
(
"sign="
+
sign
).
toString
();
// System.out.println("UrlEncode后 packageValue=" + packageValue);
return
packageValue
;
}
/**
* 创建md5摘要,规则是:按参数名称a-z排序,遇到空值的参数不参加签名。
*/
public
String
createSign
(
SortedMap
<
String
,
String
>
packageParams
)
{
StringBuffer
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="
+
this
.
getKey
());
System
.
out
.
println
(
"md5 sb:"
+
sb
);
String
sign
=
MD5RefundUtil
.
MD5Encode
(
sb
.
toString
(),
this
.
charset
)
.
toUpperCase
();
System
.
out
.
println
(
"packge签名:"
+
sign
);
return
sign
;
}
/**
* 创建package签名
*/
public
boolean
createMd5Sign
(
String
signParams
)
{
StringBuffer
sb
=
new
StringBuffer
();
Set
es
=
this
.
parameters
.
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
(!
"sign"
.
equals
(
k
)
&&
null
!=
v
&&
!
""
.
equals
(
v
))
{
sb
.
append
(
k
+
"="
+
v
+
"&"
);
}
}
// 算出摘要
String
enc
=
TenpayUtil
.
getCharacterEncoding
(
this
.
request
,
this
.
response
);
String
sign
=
MD5RefundUtil
.
MD5Encode
(
sb
.
toString
(),
enc
).
toLowerCase
();
String
tenpaySign
=
this
.
getParameter
(
"sign"
).
toLowerCase
();
// debug信息
this
.
setDebugInfo
(
sb
.
toString
()
+
" => sign:"
+
sign
+
" tenpaySign:"
+
tenpaySign
);
return
tenpaySign
.
equals
(
sign
);
}
//输出XML
public
String
parseXML
()
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"<xml>"
);
Set
es
=
this
.
parameters
.
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
)
&&
!
"appkey"
.
equals
(
k
))
{
sb
.
append
(
"<"
+
k
+
">"
+
getParameter
(
k
)
+
"</"
+
k
+
">\n"
);
}
}
sb
.
append
(
"</xml>"
);
return
sb
.
toString
();
}
/**
* 设置debug信息
*/
protected
void
setDebugInfo
(
String
debugInfo
)
{
this
.
debugInfo
=
debugInfo
;
}
public
void
setPartnerkey
(
String
partnerkey
)
{
this
.
partnerkey
=
partnerkey
;
}
public
String
getDebugInfo
()
{
return
debugInfo
;
}
public
String
getKey
()
{
return
key
;
}
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/utils/WeiXinPayUtil.java
0 → 100644
View file @
743ae98a
package
com
.
xxfc
.
platform
.
universal
.
utils
;
import
java.io.Writer
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
com.thoughtworks.xstream.XStream
;
import
com.thoughtworks.xstream.core.util.QuickWriter
;
import
com.thoughtworks.xstream.io.HierarchicalStreamWriter
;
import
com.thoughtworks.xstream.io.xml.PrettyPrintWriter
;
import
com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer
;
import
com.thoughtworks.xstream.io.xml.XppDriver
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
public
class
WeiXinPayUtil
{
private
final
static
String
WeXinPay_URL
=
"https://api.mch.weixin.qq.com/pay/unifiedorder"
;
private
final
static
String
WeXinRefund_URL
=
"https://api.mch.weixin.qq.com/secapi/pay/refund"
;
public
static
String
getPrepayId
(
String
xml
,
String
method
){
return
HTTPSUtils
.
httpRequest
(
WeXinPay_URL
,
method
,
xml
);
}
@SuppressWarnings
(
"deprecation"
)
private
static
XStream
xstream
=
new
XStream
(
/*new XppDriver() {
public HierarchicalStreamWriter createWriter(Writer out) {
return new PrettyPrintWriter(out) {
// 对所有xml节点的转换都增加CDATA标记
boolean cdata = true;
@SuppressWarnings({ "rawtypes" })
public void startNode(String name, Class clazz) {
super.startNode(name, clazz);
}
protected void writeText(QuickWriter writer, String text) {
if (cdata) {
writer.write("<![CDATA[");
writer.write(text);
writer.write("]]>");
} else {
writer.write(text);
}
}
};
}
}*/
new
XppDriver
(
new
XmlFriendlyReplacer
(
"_-"
,
"_"
){
public
HierarchicalStreamWriter
createWriter
(
Writer
out
)
{
return
new
PrettyPrintWriter
(
out
)
{
// 对所有xml节点的转换都增加CDATA标记
boolean
cdata
=
true
;
@SuppressWarnings
({
"rawtypes"
})
public
void
startNode
(
String
name
,
Class
clazz
)
{
super
.
startNode
(
name
,
clazz
);
}
protected
void
writeText
(
QuickWriter
writer
,
String
text
)
{
if
(
cdata
)
{
writer
.
write
(
"<![CDATA["
);
writer
.
write
(
text
);
writer
.
write
(
"]]>"
);
}
else
{
writer
.
write
(
text
);
}
}
};
}
})
);
public
static
String
toXml
(
WxPrepay
wxPrepay
){
xstream
.
alias
(
"xml"
,
wxPrepay
.
getClass
());
return
xstream
.
toXML
(
wxPrepay
);
}
/**
* 获取随机字符串
* @return
*/
public
static
String
getNonceStr
()
{
// 随机数
String
currTime
=
getCurrTime
();
// 8位日期
String
strTime
=
currTime
.
substring
(
8
,
currTime
.
length
());
// 四位随机数
String
strRandom
=
buildRandom
(
4
)
+
""
;
// 10位序列号,可以自行调整。
return
strTime
+
strRandom
;
}
/**
* 获取当前时间 yyyyMMddHHmmss
* @return String
*/
public
static
String
getCurrTime
()
{
Date
now
=
new
Date
();
SimpleDateFormat
outFormat
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
String
s
=
outFormat
.
format
(
now
);
return
s
;
}
/**
* 取出一个指定长度大小的随机正整数.
*
* @param length
* int 设定所取出随机数的长度。length小于11
* @return int 返回生成的随机数。
*/
public
static
int
buildRandom
(
int
length
)
{
int
num
=
1
;
double
random
=
Math
.
random
();
if
(
random
<
0.1
)
{
random
=
random
+
0.1
;
}
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
num
=
num
*
10
;
}
return
(
int
)
((
random
*
num
));
}
/**
* 元转换成分
* @param
* @return
*/
public
static
String
getMoney
(
String
amount
)
{
if
(
amount
==
null
){
return
""
;
}
// 金额转化为分为单位
String
currency
=
amount
.
replaceAll
(
"\\$|\\¥|\\,"
,
""
);
//处理包含, ¥ 或者$的金额
int
index
=
currency
.
indexOf
(
"."
);
int
length
=
currency
.
length
();
Long
amLong
=
0
l
;
if
(
index
==
-
1
){
amLong
=
Long
.
valueOf
(
currency
+
"00"
);
}
else
if
(
length
-
index
>=
3
){
amLong
=
Long
.
valueOf
((
currency
.
substring
(
0
,
index
+
3
)).
replace
(
"."
,
""
));
}
else
if
(
length
-
index
==
2
){
amLong
=
Long
.
valueOf
((
currency
.
substring
(
0
,
index
+
2
)).
replace
(
"."
,
""
)+
0
);
}
else
{
amLong
=
Long
.
valueOf
((
currency
.
substring
(
0
,
index
+
1
)).
replace
(
"."
,
""
)+
"00"
);
}
return
amLong
.
toString
();
}
/**
* ArrayToXml
* @param arr
* @return
*/
public
static
String
ArrayToXml
(
Map
<
String
,
String
>
arr
)
{
String
xml
=
"<xml>"
;
Iterator
<
Entry
<
String
,
String
>>
iter
=
arr
.
entrySet
().
iterator
();
while
(
iter
.
hasNext
())
{
Entry
<
String
,
String
>
entry
=
iter
.
next
();
String
key
=
entry
.
getKey
();
String
val
=
entry
.
getValue
();
if
(
IsNumeric
(
val
))
{
xml
+=
"<"
+
key
+
">"
+
val
+
"</"
+
key
+
">"
;
}
else
xml
+=
"<"
+
key
+
"><![CDATA["
+
val
+
"]]></"
+
key
+
">"
;
}
xml
+=
"</xml>"
;
return
xml
;
}
public
static
boolean
IsNumeric
(
String
str
)
{
if
(
str
.
matches
(
"\\d *"
))
{
return
true
;
}
else
{
return
false
;
}
}
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/utils/WxPrepay.java
0 → 100644
View file @
743ae98a
package
com
.
xxfc
.
platform
.
universal
.
utils
;
public
class
WxPrepay
{
private
String
appid
;
private
String
mch_id
;
private
String
nonce_str
;
private
String
sign
;
private
String
body
;
private
String
out_trade_no
;
private
String
attach
;
private
String
total_fee
;
private
String
spbill_create_ip
;
private
String
notify_url
;
private
String
trade_type
;
private
String
openid
;
private
String
out_refund_no
;
private
String
refund_fee
;
private
String
op_user_id
;
public
WxPrepay
(){};
public
String
getAppid
()
{
return
appid
;
}
public
void
setAppid
(
String
appid
)
{
this
.
appid
=
appid
;
}
public
String
getMch_id
()
{
return
mch_id
;
}
public
void
setMch_id
(
String
mch_id
)
{
this
.
mch_id
=
mch_id
;
}
public
String
getNonce_str
()
{
return
nonce_str
;
}
public
void
setNonce_str
(
String
nonce_str
)
{
this
.
nonce_str
=
nonce_str
;
}
public
String
getSign
()
{
return
sign
;
}
public
void
setSign
(
String
sign
)
{
this
.
sign
=
sign
;
}
public
String
getBody
()
{
return
body
;
}
public
void
setBody
(
String
body
)
{
this
.
body
=
body
;
}
public
String
getOut_trade_no
()
{
return
out_trade_no
;
}
public
void
setOut_trade_no
(
String
out_trade_no
)
{
this
.
out_trade_no
=
out_trade_no
;
}
public
String
getAttach
()
{
return
attach
;
}
public
void
setAttach
(
String
attach
)
{
this
.
attach
=
attach
;
}
public
String
getTotal_fee
()
{
return
total_fee
;
}
public
void
setTotal_fee
(
String
total_fee
)
{
this
.
total_fee
=
total_fee
;
}
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
getNotify_url
()
{
return
notify_url
;
}
public
void
setNotify_url
(
String
notify_url
)
{
this
.
notify_url
=
notify_url
;
}
public
String
getTrade_type
()
{
return
trade_type
;
}
public
void
setTrade_type
(
String
trade_type
)
{
this
.
trade_type
=
trade_type
;
}
public
String
getOpenid
()
{
return
openid
;
}
public
void
setOpenid
(
String
openid
)
{
this
.
openid
=
openid
;
}
public
String
getOut_refund_no
()
{
return
out_refund_no
;
}
public
void
setOut_refund_no
(
String
out_refund_no
)
{
this
.
out_refund_no
=
out_refund_no
;
}
public
String
getRefund_fee
()
{
return
refund_fee
;
}
public
void
setRefund_fee
(
String
refund_fee
)
{
this
.
refund_fee
=
refund_fee
;
}
public
String
getOp_user_id
()
{
return
op_user_id
;
}
public
void
setOp_user_id
(
String
op_user_id
)
{
this
.
op_user_id
=
op_user_id
;
}
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/weixin/api/WXPay.java
View file @
743ae98a
...
...
@@ -4,16 +4,14 @@ package com.xxfc.platform.universal.weixin.api;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Set
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
import
java.util.*
;
import
com.github.wxiaoqi.security.common.util.MD5
;
import
com.github.wxiaoqi.security.common.util.MD5Util
;
import
com.github.wxiaoqi.security.common.util.OrderUtil
;
import
com.github.wxiaoqi.security.common.util.process.SystemConfig
;
import
com.xxfc.platform.universal.utils.RequestHandler
;
import
com.xxfc.platform.universal.utils.WeiXinPayUtil
;
import
com.xxfc.platform.universal.utils.WxPrepay
;
import
com.xxfc.platform.universal.weixin.util.HTTPUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -377,7 +375,93 @@ public class WXPay {
System
.
out
.
println
(
response_body
);
}
public
static
String
getPackage
(
String
total_fee
,
String
body
,
String
notify_url
,
String
orderNo
,
String
spbill_create_ip
,
String
openid
,
String
appid
,
String
appsecret
){
Map
<
String
,
String
>
map
=
new
LinkedHashMap
<
String
,
String
>();
Random
random
=
new
Random
();
String
randomStr
=
MD5
.
GetMD5String
(
String
.
valueOf
(
random
.
nextInt
(
10000
)));
String
noceStr
=
MD5Util
.
MD5Encode
(
randomStr
,
"utf-8"
).
toLowerCase
();
SortedMap
<
String
,
String
>
packageParams
=
new
TreeMap
<
String
,
String
>();
packageParams
.
put
(
"appid"
,
appid
);
packageParams
.
put
(
"mch_id"
,
SystemConfig
.
WINXIN_PARTNER
);
packageParams
.
put
(
"nonce_str"
,
noceStr
);
packageParams
.
put
(
"body"
,
body
);
packageParams
.
put
(
"attach"
,
""
);
packageParams
.
put
(
"out_trade_no"
,
orderNo
);
// 这里写的金额为1 分到时修改
packageParams
.
put
(
"total_fee"
,
total_fee
);
packageParams
.
put
(
"spbill_create_ip"
,
spbill_create_ip
);
packageParams
.
put
(
"notify_url"
,
notify_url
);
String
trade_type
=
"JSAPI"
;
packageParams
.
put
(
"trade_type"
,
trade_type
);
packageParams
.
put
(
"openid"
,
openid
);
RequestHandler
reqHandler
=
new
RequestHandler
(
null
,
null
);
reqHandler
.
init
(
appid
,
appsecret
,
SystemConfig
.
WINXIN_PARTNER_KEY
);
String
sign
=
reqHandler
.
createSign
(
packageParams
);
WxPrepay
wxPrepay
=
new
WxPrepay
();
wxPrepay
.
setAppid
(
appid
);
wxPrepay
.
setMch_id
(
SystemConfig
.
WINXIN_PARTNER
);
wxPrepay
.
setNonce_str
(
noceStr
);
wxPrepay
.
setSign
(
sign
);
wxPrepay
.
setBody
(
body
);
wxPrepay
.
setOut_trade_no
(
orderNo
);
wxPrepay
.
setTotal_fee
(
total_fee
);
wxPrepay
.
setSpbill_create_ip
(
spbill_create_ip
);
wxPrepay
.
setNotify_url
(
notify_url
);
wxPrepay
.
setTrade_type
(
trade_type
);
wxPrepay
.
setOpenid
(
openid
);
wxPrepay
.
setAttach
(
""
);
String
xml
=
WeiXinPayUtil
.
toXml
(
wxPrepay
);
log
.
error
(
"post_prepay_xml: "
+
xml
);
//获取prepay_id
map
=
StringtoMap
(
WeiXinPayUtil
.
getPrepayId
(
xml
,
"POST"
));
//获取prepay_id后,拼接最后请求支付所需要的package
SortedMap
<
String
,
String
>
finalpackage
=
new
TreeMap
<
String
,
String
>();
String
timestamp
=
OrderUtil
.
GetTimestamp
();
String
packages
=
"prepay_id="
+
map
.
get
(
"prepay_id"
);
finalpackage
.
put
(
"appId"
,
appid
);
finalpackage
.
put
(
"timeStamp"
,
timestamp
);
finalpackage
.
put
(
"nonceStr"
,
noceStr
);
finalpackage
.
put
(
"package"
,
packages
);
finalpackage
.
put
(
"signType"
,
"MD5"
);
//要签名
String
finalsign
=
reqHandler
.
createSign
(
finalpackage
);
String
finaPackage
=
"\"appId\":\""
+
appid
+
"\",\"timeStamp\":\""
+
timestamp
+
"\",\"nonceStr\":\""
+
noceStr
+
"\",\"package\":\""
+
packages
+
"\",\"signType\" : \"MD5"
+
"\",\"paySign\":\""
+
finalsign
+
"\""
;
return
finaPackage
;
}
public
static
Map
<
String
,
String
>
StringtoMap
(
String
str
){
log
.
error
(
"respon_prepay_xml: "
+
str
);
Map
<
String
,
String
>
map
=
new
LinkedHashMap
<
String
,
String
>();
try
{
Document
document
=
DocumentHelper
.
parseText
(
str
);
Element
root
=
document
.
getRootElement
();
List
<
Element
>
elementList
=
root
.
elements
();
for
(
Element
e
:
elementList
){
map
.
put
(
e
.
getName
(),
e
.
getText
());
}
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
return
map
;
}
}
\ No newline at end of file
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/biz/OrderPayBiz.java
View file @
743ae98a
...
...
@@ -65,6 +65,8 @@ public class OrderPayBiz extends BaseBiz<OrderPayMapper, OrderPay> {
String
weixinHost
;
@Value
(
"${wx.appid}"
)
private
String
wy_appid
;
@Value
(
"${wx.appSercet}"
)
private
String
wy_secret
;
...
...
@@ -114,7 +116,7 @@ public class OrderPayBiz extends BaseBiz<OrderPayMapper, OrderPay> {
jsParam
=
generateAliPayment
(
orderPayVo
,
notifyUrl
);
}
else
if
(
type
==
3
&&
payWay
==
1
){
sellerAccount
=
SystemConfig
.
APP_PARTNER
;
jsParam
=
WXPay
.
webPay
(
amount
+
""
,
orderPayVo
.
getBody
(),
notify_url
,
trade_no
,
orderPayVo
.
getBuyerIp
(),
orderPayVo
.
getBuyerAccount
(),
wy_appid
);
jsParam
=
WXPay
.
getPackage
(
amount
+
""
,
orderPayVo
.
getBody
(),
notify_url
,
trade_no
,
orderPayVo
.
getBuyerIp
(),
orderPayVo
.
getBuyerAccount
(),
wy_appid
,
wy_secret
);
}
log
.
info
(
"报名费回调路径jsParam:"
+
jsParam
);
if
(!
StringUtils
.
isBlank
(
jsParam
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment