Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
payment
Project
Project
Details
Activity
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
曲欣亮
payment
Commits
e3d8a118
Commit
e3d8a118
authored
Oct 16, 2018
by
zhangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
8dfd0ff5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
276 additions
and
263 deletions
+276
-263
WxApiController.java
...in/java/com/egolm/payment/controller/WxApiController.java
+275
-9
WxMiniApiController.java
...ava/com/egolm/payment/controller/WxMiniApiController.java
+0
-253
application-dev.properties
src/main/resources/application-dev.properties
+1
-1
No files found.
src/main/java/com/egolm/payment/controller/WxApiController.java
View file @
e3d8a118
package
com
.
egolm
.
payment
.
controller
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.egolm.common.DateUtil
;
import
com.egolm.common.StringUtil
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.common.web.ServletUtil
;
import
com.egolm.payment.service.WxChatService
;
import
com.egolm.payment.util.PayContstrant
;
import
com.egolm.payment.util.WxSignUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
@Api
(
tags
={
"微信公众号接口管理"
})
@RestController
@RequestMapping
(
"wx"
)
@RequestMapping
(
"wx
chat
"
)
public
class
WxApiController
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
WxApiController
.
class
);
@Autowired
private
WxChatService
wxChatService
;
/**
*
* <p>Title: 微信統一下单接口 </p>
* <p>Description: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1&index=1 </p>
* 传参请按微信API的参数属性名传值
* @param request
* @param response
* @return
*/
@ApiOperation
(
"微信統一下单接口"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"terminal"
,
dataType
=
"String"
,
required
=
false
,
value
=
"终端标识"
,
defaultValue
=
"wechat"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"langID"
,
dataType
=
"String"
,
required
=
false
,
value
=
"语言"
,
defaultValue
=
"936"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"body"
,
dataType
=
"String"
,
required
=
true
,
value
=
"商品描述"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"detail"
,
dataType
=
"String"
,
required
=
false
,
value
=
"商品详情"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"out_trade_no"
,
dataType
=
"String"
,
required
=
true
,
value
=
"商户订单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"total_fee"
,
dataType
=
"String"
,
required
=
true
,
value
=
"总金额(分)"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"openid"
,
dataType
=
"String"
,
required
=
false
,
value
=
"用户标识"
,
defaultValue
=
""
)
})
@RequestMapping
(
value
=
"/unifiedorder"
,
method
=
RequestMethod
.
GET
)
public
String
unifiedorder
(
HttpServletRequest
request
,
HttpServletResponse
response
){
try
{
String
terminal
=
request
.
getParameter
(
"terminal"
);
String
langID
=
request
.
getParameter
(
"langID"
);
SortedMap
<
Object
,
Object
>
params
=
new
TreeMap
<
Object
,
Object
>();
String
appid
=
""
;
String
md5Key
=
""
;
Map
<
String
,
Object
>
systemCtrlMap
=
wxChatService
.
loadAppID
(
PayContstrant
.
WX_MINI_APP_KEY
,
langID
);
if
(
systemCtrlMap
!=
null
)
{
appid
=
systemCtrlMap
.
get
(
"sValue1"
)+
""
;
String
mch_id
=
systemCtrlMap
.
get
(
"sValue3"
)+
""
;
String
notify_url
=
systemCtrlMap
.
get
(
"sValue4"
)+
""
;
md5Key
=
systemCtrlMap
.
get
(
"sValue5"
)+
""
;
params
.
put
(
"appid"
,
appid
);
params
.
put
(
"mch_id"
,
mch_id
);
params
.
put
(
"notify_url"
,
notify_url
);
params
.
put
(
"md5Key"
,
md5Key
);
if
(!
StringUtil
.
isNotEmpty
(
appid
,
mch_id
,
notify_url
,
md5Key
))
{
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"支付失败"
).
set
(
"errorMsg"
,
"数据字典参数配置不完整"
).
toJson
();
}
}
else
{
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"支付失败"
).
set
(
"errorMsg"
,
"数据字典参数未配置"
).
toJson
();
}
params
.
put
(
"nonce_str"
,
StringUtil
.
getNonceStr
());
params
.
put
(
"sign_type"
,
"MD5"
);
params
.
put
(
"fee_type"
,
"CNY"
);
params
.
put
(
"spbill_create_ip"
,
ServletUtil
.
getLocalIP
());
params
.
put
(
"trade_type"
,
"JSAPI"
);
params
.
put
(
"body"
,
request
.
getParameter
(
"body"
)==
null
?
""
:
request
.
getParameter
(
"body"
));
params
.
put
(
"detail"
,
request
.
getParameter
(
"detail"
)==
null
?
""
:
request
.
getParameter
(
"detail"
));
params
.
put
(
"out_trade_no"
,
request
.
getParameter
(
"out_trade_no"
)==
null
?
""
:
request
.
getParameter
(
"out_trade_no"
));
params
.
put
(
"total_fee"
,
request
.
getParameter
(
"total_fee"
)==
null
?
""
:
request
.
getParameter
(
"total_fee"
));
params
.
put
(
"openid"
,
request
.
getParameter
(
"openid"
)==
null
?
""
:
request
.
getParameter
(
"openid"
));
Map
<
String
,
String
>
resultMap
=
wxChatService
.
unifiedorder
(
params
);
String
return_code
=
resultMap
.
get
(
"return_code"
);
String
result_code
=
resultMap
.
get
(
"result_code"
);
if
(
return_code
.
equals
(
"SUCCESS"
)
&&
result_code
.
equals
(
"SUCCESS"
)){
//返回前端支付需要的参数
String
return_sign
=
resultMap
.
get
(
"sign"
);
// 返回的签名
resultMap
.
put
(
"md5Key"
,
md5Key
);
if
(!
WxSignUtil
.
checkSign
(
resultMap
,
return_sign
)){
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
set
(
"errorMsg"
,
"返回结果签名不一致"
).
toJson
();
}
String
prepay_id
=
resultMap
.
get
(
"prepay_id"
);
String
trade_type
=
resultMap
.
get
(
"trade_type"
);
String
packageStr
=
"prepay_id="
+
prepay_id
;
String
payNonceStr
=
StringUtil
.
getNonceStr
();
String
timeStampStr
=
DateUtil
.
getTimeStamp
();
SortedMap
<
Object
,
Object
>
payParams
=
new
TreeMap
<
Object
,
Object
>();
payParams
.
put
(
"appId"
,
appid
);
payParams
.
put
(
"timeStamp"
,
timeStampStr
);
payParams
.
put
(
"nonceStr"
,
payNonceStr
);
payParams
.
put
(
"package"
,
packageStr
);
payParams
.
put
(
"signType"
,
"MD5"
);
payParams
.
put
(
"md5Key"
,
md5Key
);
String
paySign
=
WxSignUtil
.
createSign
(
payParams
);
return
Rjx
.
jsonOk
().
set
(
"package"
,
packageStr
).
set
(
"trade_type"
,
trade_type
).
set
(
"nonceStr"
,
payNonceStr
).
set
(
"timeStamp"
,
timeStampStr
).
set
(
"paySign"
,
paySign
).
toJson
();
}
if
(
return_code
.
equals
(
"FAIL"
)){
String
return_msg
=
resultMap
.
get
(
"return_msg"
);
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
set
(
"errorMsg"
,
return_msg
).
toJson
();
}
if
(
return_code
.
equals
(
"SUCCESS"
)
&&
result_code
.
equals
(
"FAIL"
)){
String
err_code
=
resultMap
.
get
(
"err_code"
);
String
err_code_des
=
resultMap
.
get
(
"err_code_des"
);
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
set
(
"errorMsg"
,
err_code
).
set
(
"err_code_des"
,
err_code_des
).
toJson
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
set
(
"errorMsg"
,
"生成预支付订单异常"
).
toJson
();
}
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
toJson
();
}
@ApiOperation
(
"测试"
)
@ApiImplicitParams
({
})
@RequestMapping
(
value
=
"/t"
,
method
=
RequestMethod
.
POST
)
public
String
sms
(
HttpServletRequest
request
)
{
return
"1111"
;
/**
* 申请退款
* <p>Title: https://api.mch.weixin.qq.com/secapi/pay/refund</p>
* <p>Description: </p>
* @param request
* @param response
* @return
*/
@ApiOperation
(
"申请退款"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"terminal"
,
dataType
=
"String"
,
required
=
false
,
value
=
"终端标识"
,
defaultValue
=
"wechat"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"langID"
,
dataType
=
"String"
,
required
=
false
,
value
=
"语言"
,
defaultValue
=
"936"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"transaction_id"
,
dataType
=
"String"
,
required
=
true
,
value
=
"微信订单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"out_trade_no"
,
dataType
=
"String"
,
required
=
false
,
value
=
"商户订单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"out_refund_no"
,
dataType
=
"String"
,
required
=
true
,
value
=
"商户退款单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"total_fee"
,
dataType
=
"String"
,
required
=
true
,
value
=
"订单金额(分)"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"refund_fee"
,
dataType
=
"String"
,
required
=
false
,
value
=
"申请退款金额(分)"
,
defaultValue
=
""
),
})
@RequestMapping
(
value
=
"/refund"
,
method
=
RequestMethod
.
GET
)
public
String
refund
(
HttpServletRequest
request
,
HttpServletResponse
response
){
try
{
String
terminal
=
request
.
getParameter
(
"terminal"
);
String
langID
=
request
.
getParameter
(
"langID"
);
SortedMap
<
Object
,
Object
>
params
=
new
TreeMap
<
Object
,
Object
>();
String
appid
=
""
;
String
mch_id
=
""
;
String
md5Key
=
""
;
Map
<
String
,
Object
>
systemCtrlMap
=
wxChatService
.
loadAppID
(
PayContstrant
.
WX_MINI_APP_KEY
,
langID
);
if
(
systemCtrlMap
!=
null
)
{
appid
=
systemCtrlMap
.
get
(
"sValue1"
)+
""
;
mch_id
=
systemCtrlMap
.
get
(
"sValue3"
)+
""
;
md5Key
=
systemCtrlMap
.
get
(
"sValue5"
)+
""
;
if
(!
StringUtil
.
isNotEmpty
(
appid
,
mch_id
,
md5Key
))
{
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"支付失败"
).
set
(
"errorMsg"
,
"数据字典参数配置不完整"
).
toJson
();
}
}
else
{
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"支付失败"
).
set
(
"errorMsg"
,
"数据字典参数未配置"
).
toJson
();
}
params
.
put
(
"appid"
,
appid
);
params
.
put
(
"mch_id"
,
mch_id
);
params
.
put
(
"md5Key"
,
md5Key
);
params
.
put
(
"nonce_str"
,
StringUtil
.
getNonceStr
());
//随机字符串
params
.
put
(
"sign_type"
,
"MD5"
);
params
.
put
(
"transaction_id"
,
request
.
getParameter
(
"transaction_id"
)==
null
?
""
:
request
.
getParameter
(
"transaction_id"
));
params
.
put
(
"out_trade_no"
,
request
.
getParameter
(
"out_trade_no"
)==
null
?
""
:
request
.
getParameter
(
"out_trade_no"
));
params
.
put
(
"out_refund_no"
,
request
.
getParameter
(
"out_refund_no"
)==
null
?
""
:
request
.
getParameter
(
"out_refund_no"
));
params
.
put
(
"total_fee"
,
request
.
getParameter
(
"total_fee"
)==
null
?
""
:
request
.
getParameter
(
"total_fee"
));
params
.
put
(
"refund_fee"
,
request
.
getParameter
(
"refund_fee"
)==
null
?
""
:
request
.
getParameter
(
"refund_fee"
));
Map
<
String
,
String
>
resultMap
=
wxChatService
.
refund
(
params
);
String
return_code
=
resultMap
.
get
(
"return_code"
);
String
result_code
=
resultMap
.
get
(
"result_code"
);
if
(
return_code
.
equals
(
"SUCCESS"
)
&&
result_code
.
equals
(
"SUCCESS"
)){
//返回前端支付需要的参数
String
return_sign
=
resultMap
.
get
(
"sign"
);
// 返回的签名
resultMap
.
put
(
"md5Key"
,
md5Key
);
if
(!
WxSignUtil
.
checkSign
(
resultMap
,
return_sign
)){
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"退款失败"
).
set
(
"errorMsg"
,
"返回结果签名不一致"
).
toJson
();
}
return
Rjx
.
jsonOk
().
setMessage
(
"微信退款成功"
).
toJson
();
}
if
(
return_code
.
equals
(
"FAIL"
)){
String
return_msg
=
resultMap
.
get
(
"return_msg"
);
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"退款失败"
).
set
(
"errorMsg"
,
return_msg
).
toJson
();
}
if
(
return_code
.
equals
(
"SUCCESS"
)
&&
result_code
.
equals
(
"FAIL"
)){
String
err_code
=
resultMap
.
get
(
"err_code"
);
String
err_code_des
=
resultMap
.
get
(
"err_code_des"
);
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"退款失败"
).
set
(
"err_code"
,
err_code
).
set
(
"errorMsg"
,
err_code_des
).
toJson
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
@ApiOperation
(
"获取微信支付流水号(没做完)"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"terminal"
,
dataType
=
"String"
,
required
=
true
,
value
=
"终端标识"
,
defaultValue
=
"wechat"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"langID"
,
dataType
=
"String"
,
required
=
true
,
value
=
"语言"
,
defaultValue
=
"936"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"orderId"
,
dataType
=
"String"
,
required
=
true
,
value
=
"订单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"status"
,
dataType
=
"String"
,
required
=
true
,
value
=
"查询状态(PAY,REFUND)"
,
defaultValue
=
""
)
})
@RequestMapping
(
value
=
"/getWxPayFlow"
,
method
=
RequestMethod
.
GET
)
public
String
getWxPayFlow
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
String
terminal
=
request
.
getParameter
(
"terminal"
);
String
langID
=
request
.
getParameter
(
"langID"
);
String
orderId
=
request
.
getParameter
(
"orderId"
);
String
status
=
request
.
getParameter
(
"status"
);
if
(!
StringUtil
.
isNotEmpty
(
terminal
,
langID
,
orderId
,
status
)){
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"参数不能为空"
).
toJson
();
}
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
params
.
put
(
"orderId"
,
orderId
);
params
.
put
(
"status"
,
status
);
try
{
/*WxPayFlow wxPayFlow = wxApiService.getWxPayFlow(params);
if(wxPayFlow == null){
wxPayFlow = new WxPayFlow();
}
Map<String,Object> resultMap = new HashMap<String,Object>();
resultMap.put("orderId", wxPayFlow.getOrderid()==null?"":wxPayFlow.getOrderid());
resultMap.put("status", wxPayFlow.getStatus()==null?"":wxPayFlow.getStatus());
resultMap.put("transactionid", wxPayFlow.getTransactionid()==null?"":wxPayFlow.getTransactionid());
resultMap.put("totalFee", wxPayFlow.getTotalfee()==null?0:wxPayFlow.getTotalfee());
resultMap.put("refundId", wxPayFlow.getRefundid()==null?"":wxPayFlow.getRefundid());
resultMap.put("refundFee", wxPayFlow.getRefundfee()==null?0:wxPayFlow.getRefundfee());
resultMap.put("cashFee", wxPayFlow.getCashfee()==null?0:wxPayFlow.getCashfee());
resultMap.put("couponRefundCount", wxPayFlow.getCouponrefundcount()==null?0:wxPayFlow.getCouponrefundcount());
resultMap.put("cashRefundFee", wxPayFlow.getCashrefundfee()==null?0:wxPayFlow.getCashrefundfee());*/
return
Rjx
.
jsonOk
().
toJson
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"查询异常"
).
toJson
();
}
}
}
src/main/java/com/egolm/payment/controller/WxMiniApiController.java
View file @
e3d8a118
...
...
@@ -90,258 +90,5 @@ public class WxMiniApiController {
}
/**
*
* <p>Title: 微信統一下单接口 </p>
* <p>Description: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1&index=1 </p>
* 传参请按微信API的参数属性名传值
* @param request
* @param response
* @return
*/
@ApiOperation
(
"微信統一下单接口"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"terminal"
,
dataType
=
"String"
,
required
=
false
,
value
=
"终端标识"
,
defaultValue
=
"wechat"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"langID"
,
dataType
=
"String"
,
required
=
false
,
value
=
"语言"
,
defaultValue
=
"936"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"body"
,
dataType
=
"String"
,
required
=
true
,
value
=
"商品描述"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"detail"
,
dataType
=
"String"
,
required
=
false
,
value
=
"商品详情"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"out_trade_no"
,
dataType
=
"String"
,
required
=
true
,
value
=
"商户订单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"total_fee"
,
dataType
=
"String"
,
required
=
true
,
value
=
"总金额(分)"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"openid"
,
dataType
=
"String"
,
required
=
false
,
value
=
"用户标识"
,
defaultValue
=
""
)
})
@RequestMapping
(
value
=
"/unifiedorder"
,
method
=
RequestMethod
.
GET
)
public
String
unifiedorder
(
HttpServletRequest
request
,
HttpServletResponse
response
){
try
{
String
terminal
=
request
.
getParameter
(
"terminal"
);
String
langID
=
request
.
getParameter
(
"langID"
);
SortedMap
<
Object
,
Object
>
params
=
new
TreeMap
<
Object
,
Object
>();
String
appid
=
""
;
String
md5Key
=
""
;
Map
<
String
,
Object
>
systemCtrlMap
=
wxChatService
.
loadAppID
(
PayContstrant
.
WX_MINI_APP_KEY
,
langID
);
if
(
systemCtrlMap
!=
null
)
{
appid
=
systemCtrlMap
.
get
(
"sValue1"
)+
""
;
String
mch_id
=
systemCtrlMap
.
get
(
"sValue3"
)+
""
;
String
notify_url
=
systemCtrlMap
.
get
(
"sValue4"
)+
""
;
md5Key
=
systemCtrlMap
.
get
(
"sValue5"
)+
""
;
params
.
put
(
"appid"
,
appid
);
params
.
put
(
"mch_id"
,
mch_id
);
params
.
put
(
"notify_url"
,
notify_url
);
params
.
put
(
"md5Key"
,
md5Key
);
if
(!
StringUtil
.
isNotEmpty
(
appid
,
mch_id
,
notify_url
,
md5Key
))
{
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"支付失败"
).
set
(
"errorMsg"
,
"数据字典参数配置不完整"
).
toJson
();
}
}
else
{
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"支付失败"
).
set
(
"errorMsg"
,
"数据字典参数未配置"
).
toJson
();
}
params
.
put
(
"nonce_str"
,
StringUtil
.
getNonceStr
());
params
.
put
(
"sign_type"
,
"MD5"
);
params
.
put
(
"fee_type"
,
"CNY"
);
params
.
put
(
"spbill_create_ip"
,
ServletUtil
.
getLocalIP
());
params
.
put
(
"trade_type"
,
"JSAPI"
);
params
.
put
(
"body"
,
request
.
getParameter
(
"body"
)==
null
?
""
:
request
.
getParameter
(
"body"
));
params
.
put
(
"detail"
,
request
.
getParameter
(
"detail"
)==
null
?
""
:
request
.
getParameter
(
"detail"
));
params
.
put
(
"out_trade_no"
,
request
.
getParameter
(
"out_trade_no"
)==
null
?
""
:
request
.
getParameter
(
"out_trade_no"
));
params
.
put
(
"total_fee"
,
request
.
getParameter
(
"total_fee"
)==
null
?
""
:
request
.
getParameter
(
"total_fee"
));
params
.
put
(
"openid"
,
request
.
getParameter
(
"openid"
)==
null
?
""
:
request
.
getParameter
(
"openid"
));
Map
<
String
,
String
>
resultMap
=
wxChatService
.
unifiedorder
(
params
);
String
return_code
=
resultMap
.
get
(
"return_code"
);
String
result_code
=
resultMap
.
get
(
"result_code"
);
if
(
return_code
.
equals
(
"SUCCESS"
)
&&
result_code
.
equals
(
"SUCCESS"
)){
//返回前端支付需要的参数
String
return_sign
=
resultMap
.
get
(
"sign"
);
// 返回的签名
resultMap
.
put
(
"md5Key"
,
md5Key
);
if
(!
WxSignUtil
.
checkSign
(
resultMap
,
return_sign
)){
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
set
(
"errorMsg"
,
"返回结果签名不一致"
).
toJson
();
}
String
prepay_id
=
resultMap
.
get
(
"prepay_id"
);
String
trade_type
=
resultMap
.
get
(
"trade_type"
);
String
packageStr
=
"prepay_id="
+
prepay_id
;
String
payNonceStr
=
StringUtil
.
getNonceStr
();
String
timeStampStr
=
DateUtil
.
getTimeStamp
();
SortedMap
<
Object
,
Object
>
payParams
=
new
TreeMap
<
Object
,
Object
>();
payParams
.
put
(
"appId"
,
appid
);
payParams
.
put
(
"timeStamp"
,
timeStampStr
);
payParams
.
put
(
"nonceStr"
,
payNonceStr
);
payParams
.
put
(
"package"
,
packageStr
);
payParams
.
put
(
"signType"
,
"MD5"
);
payParams
.
put
(
"md5Key"
,
md5Key
);
String
paySign
=
WxSignUtil
.
createSign
(
payParams
);
return
Rjx
.
jsonOk
().
set
(
"package"
,
packageStr
).
set
(
"trade_type"
,
trade_type
).
set
(
"nonceStr"
,
payNonceStr
).
set
(
"timeStamp"
,
timeStampStr
).
set
(
"paySign"
,
paySign
).
toJson
();
}
if
(
return_code
.
equals
(
"FAIL"
)){
String
return_msg
=
resultMap
.
get
(
"return_msg"
);
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
set
(
"errorMsg"
,
return_msg
).
toJson
();
}
if
(
return_code
.
equals
(
"SUCCESS"
)
&&
result_code
.
equals
(
"FAIL"
)){
String
err_code
=
resultMap
.
get
(
"err_code"
);
String
err_code_des
=
resultMap
.
get
(
"err_code_des"
);
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
set
(
"errorMsg"
,
err_code
).
set
(
"err_code_des"
,
err_code_des
).
toJson
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
set
(
"errorMsg"
,
"生成预支付订单异常"
).
toJson
();
}
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"微信下单失败"
).
toJson
();
}
/**
* 申请退款
* <p>Title: https://api.mch.weixin.qq.com/secapi/pay/refund</p>
* <p>Description: </p>
* @param request
* @param response
* @return
*/
@ApiOperation
(
"申请退款"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"terminal"
,
dataType
=
"String"
,
required
=
false
,
value
=
"终端标识"
,
defaultValue
=
"wechat"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"langID"
,
dataType
=
"String"
,
required
=
false
,
value
=
"语言"
,
defaultValue
=
"936"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"transaction_id"
,
dataType
=
"String"
,
required
=
true
,
value
=
"微信订单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"out_trade_no"
,
dataType
=
"String"
,
required
=
false
,
value
=
"商户订单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"out_refund_no"
,
dataType
=
"String"
,
required
=
true
,
value
=
"商户退款单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"total_fee"
,
dataType
=
"String"
,
required
=
true
,
value
=
"订单金额(分)"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"refund_fee"
,
dataType
=
"String"
,
required
=
false
,
value
=
"申请退款金额(分)"
,
defaultValue
=
""
),
})
@RequestMapping
(
value
=
"/refund"
,
method
=
RequestMethod
.
GET
)
public
String
refund
(
HttpServletRequest
request
,
HttpServletResponse
response
){
try
{
String
terminal
=
request
.
getParameter
(
"terminal"
);
String
langID
=
request
.
getParameter
(
"langID"
);
SortedMap
<
Object
,
Object
>
params
=
new
TreeMap
<
Object
,
Object
>();
String
appid
=
""
;
String
mch_id
=
""
;
String
md5Key
=
""
;
Map
<
String
,
Object
>
systemCtrlMap
=
wxChatService
.
loadAppID
(
PayContstrant
.
WX_MINI_APP_KEY
,
langID
);
if
(
systemCtrlMap
!=
null
)
{
appid
=
systemCtrlMap
.
get
(
"sValue1"
)+
""
;
mch_id
=
systemCtrlMap
.
get
(
"sValue3"
)+
""
;
md5Key
=
systemCtrlMap
.
get
(
"sValue5"
)+
""
;
if
(!
StringUtil
.
isNotEmpty
(
appid
,
mch_id
,
md5Key
))
{
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"支付失败"
).
set
(
"errorMsg"
,
"数据字典参数配置不完整"
).
toJson
();
}
}
else
{
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"支付失败"
).
set
(
"errorMsg"
,
"数据字典参数未配置"
).
toJson
();
}
params
.
put
(
"appid"
,
appid
);
params
.
put
(
"mch_id"
,
mch_id
);
params
.
put
(
"md5Key"
,
md5Key
);
params
.
put
(
"nonce_str"
,
StringUtil
.
getNonceStr
());
//随机字符串
params
.
put
(
"sign_type"
,
"MD5"
);
params
.
put
(
"transaction_id"
,
request
.
getParameter
(
"transaction_id"
)==
null
?
""
:
request
.
getParameter
(
"transaction_id"
));
params
.
put
(
"out_trade_no"
,
request
.
getParameter
(
"out_trade_no"
)==
null
?
""
:
request
.
getParameter
(
"out_trade_no"
));
params
.
put
(
"out_refund_no"
,
request
.
getParameter
(
"out_refund_no"
)==
null
?
""
:
request
.
getParameter
(
"out_refund_no"
));
params
.
put
(
"total_fee"
,
request
.
getParameter
(
"total_fee"
)==
null
?
""
:
request
.
getParameter
(
"total_fee"
));
params
.
put
(
"refund_fee"
,
request
.
getParameter
(
"refund_fee"
)==
null
?
""
:
request
.
getParameter
(
"refund_fee"
));
Map
<
String
,
String
>
resultMap
=
wxChatService
.
refund
(
params
);
String
return_code
=
resultMap
.
get
(
"return_code"
);
String
result_code
=
resultMap
.
get
(
"result_code"
);
if
(
return_code
.
equals
(
"SUCCESS"
)
&&
result_code
.
equals
(
"SUCCESS"
)){
//返回前端支付需要的参数
String
return_sign
=
resultMap
.
get
(
"sign"
);
// 返回的签名
resultMap
.
put
(
"md5Key"
,
md5Key
);
if
(!
WxSignUtil
.
checkSign
(
resultMap
,
return_sign
)){
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"退款失败"
).
set
(
"errorMsg"
,
"返回结果签名不一致"
).
toJson
();
}
return
Rjx
.
jsonOk
().
setMessage
(
"微信退款成功"
).
toJson
();
}
if
(
return_code
.
equals
(
"FAIL"
)){
String
return_msg
=
resultMap
.
get
(
"return_msg"
);
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"退款失败"
).
set
(
"errorMsg"
,
return_msg
).
toJson
();
}
if
(
return_code
.
equals
(
"SUCCESS"
)
&&
result_code
.
equals
(
"FAIL"
)){
String
err_code
=
resultMap
.
get
(
"err_code"
);
String
err_code_des
=
resultMap
.
get
(
"err_code_des"
);
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"退款失败"
).
set
(
"err_code"
,
err_code
).
set
(
"errorMsg"
,
err_code_des
).
toJson
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
@ApiOperation
(
"获取微信支付流水号(没做完)"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"terminal"
,
dataType
=
"String"
,
required
=
true
,
value
=
"终端标识"
,
defaultValue
=
"wechat"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"langID"
,
dataType
=
"String"
,
required
=
true
,
value
=
"语言"
,
defaultValue
=
"936"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"orderId"
,
dataType
=
"String"
,
required
=
true
,
value
=
"订单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"status"
,
dataType
=
"String"
,
required
=
true
,
value
=
"查询状态(PAY,REFUND)"
,
defaultValue
=
""
)
})
@RequestMapping
(
value
=
"/getWxPayFlow"
,
method
=
RequestMethod
.
GET
)
public
String
getWxPayFlow
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
String
terminal
=
request
.
getParameter
(
"terminal"
);
String
langID
=
request
.
getParameter
(
"langID"
);
String
orderId
=
request
.
getParameter
(
"orderId"
);
String
status
=
request
.
getParameter
(
"status"
);
if
(!
StringUtil
.
isNotEmpty
(
terminal
,
langID
,
orderId
,
status
)){
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"参数不能为空"
).
toJson
();
}
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
params
.
put
(
"orderId"
,
orderId
);
params
.
put
(
"status"
,
status
);
try
{
/*WxPayFlow wxPayFlow = wxApiService.getWxPayFlow(params);
if(wxPayFlow == null){
wxPayFlow = new WxPayFlow();
}
Map<String,Object> resultMap = new HashMap<String,Object>();
resultMap.put("orderId", wxPayFlow.getOrderid()==null?"":wxPayFlow.getOrderid());
resultMap.put("status", wxPayFlow.getStatus()==null?"":wxPayFlow.getStatus());
resultMap.put("transactionid", wxPayFlow.getTransactionid()==null?"":wxPayFlow.getTransactionid());
resultMap.put("totalFee", wxPayFlow.getTotalfee()==null?0:wxPayFlow.getTotalfee());
resultMap.put("refundId", wxPayFlow.getRefundid()==null?"":wxPayFlow.getRefundid());
resultMap.put("refundFee", wxPayFlow.getRefundfee()==null?0:wxPayFlow.getRefundfee());
resultMap.put("cashFee", wxPayFlow.getCashfee()==null?0:wxPayFlow.getCashfee());
resultMap.put("couponRefundCount", wxPayFlow.getCouponrefundcount()==null?0:wxPayFlow.getCouponrefundcount());
resultMap.put("cashRefundFee", wxPayFlow.getCashrefundfee()==null?0:wxPayFlow.getCashrefundfee());*/
return
Rjx
.
jsonOk
().
toJson
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
Rjx
.
jsonErr
().
setCode
(-
100
).
setMessage
(
"查询异常"
).
toJson
();
}
}
}
src/main/resources/application-dev.properties
View file @
e3d8a118
...
...
@@ -36,4 +36,4 @@ spring.redis.pool.min-idle=0
#微信退款证书地址
wx.refund.ssl.path
=
\ No newline at end of file
wx.refund.ssl.path
=
/data/apps/boot/cert/apiclient_cert_egolm.p12
\ No newline at end of file
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