Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
youka-api
Overview
Overview
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
java-youka-wallet
youka-api
Commits
5b25274c
Commit
5b25274c
authored
Apr 20, 2018
by
Java-聂换换
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支付宝支付
parent
c8b4959f
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
215 additions
and
15 deletions
+215
-15
AlipayConfig.java
src/main/java/com/thinkgem/jeesite/modules/pay/alipay/config/AlipayConfig.java
+5
-0
AlipayService.java
src/main/java/com/thinkgem/jeesite/modules/pay/alipay/service/AlipayService.java
+24
-14
PayApiController.java
src/main/java/com/thinkgem/jeesite/modules/pay/api/PayApiController.java
+94
-1
PayBackDto.java
src/main/java/com/thinkgem/jeesite/modules/pay/juhezhong/dto/PayBackDto.java
+10
-0
PayApiService.java
src/main/java/com/thinkgem/jeesite/modules/pay/service/PayApiService.java
+68
-0
JuHeZhongPayRequest.java
src/main/java/com/thinkgem/jeesite/modules/user/bean/JuHeZhongPayRequest.java
+10
-0
UserApiService.java
src/main/java/com/thinkgem/jeesite/modules/user/service/UserApiService.java
+4
-0
No files found.
src/main/java/com/thinkgem/jeesite/modules/pay/alipay/config/AlipayConfig.java
0 → 100644
View file @
5b25274c
package
com
.
thinkgem
.
jeesite
.
modules
.
pay
.
alipay
.
config
;
public
class
AlipayConfig
{
public
static
final
String
TIMEOUTEXPRESS
=
"30m"
;
}
src/main/java/com/thinkgem/jeesite/modules/pay/alipay/service/AlipayService.java
View file @
5b25274c
...
...
@@ -16,7 +16,10 @@ import com.alipay.api.response.AlipayTradeOrderSettleResponse;
import
com.thinkgem.jeesite.common.config.Global
;
import
com.thinkgem.jeesite.common.mapper.JsonMapper
;
import
com.thinkgem.jeesite.common.utils.IdGen
;
import
com.thinkgem.jeesite.modules.pay.alipay.config.AlipayConfig
;
import
com.thinkgem.jeesite.modules.pay.juhezhong.utils.MakeOrderNum
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
...
...
@@ -27,6 +30,8 @@ import java.util.*;
import
static
com
.
alipay
.
api
.
AlipayConstants
.
APP_ID
;
import
static
com
.
alipay
.
api
.
AlipayConstants
.
CHARSET
;
@Service
@Transactional
public
class
AlipayService
{
public
JSONObject
alipay
(
JSONObject
dto
)
throws
AlipayApiException
{
...
...
@@ -71,7 +76,6 @@ public class AlipayService {
public
static
void
main
(
String
[]
args
)
throws
AlipayApiException
{
AlipayService
alipayService
=
new
AlipayService
();
JSONObject
dto
=
new
JSONObject
();
// dto.put("out_request_no", MakeOrderNum.makeOrderNum());// 结算请求流水号 开发者自行生成并保证唯一性
// dto.put("trade_no",IdGen.randomBase62(64)); // 支付宝订单号
// JSONObject royalty_parameters = new JSONObject(); // 分账明细信息
...
...
@@ -81,35 +85,41 @@ public class AlipayService {
// royalty_parameters.put("amount_percentage","100"); // 分账信息中分账百分比。取值范围为大于0,少于或等于100的整数。
// royalty_parameters.put("desc","desc");
// dto.put("operator_id","operator_id");// 操作员id 可选
alipayService
.
alipay
(
dto
);
alipayService
.
aliPay
(
"0.01"
,
new
HashMap
<>());
// alipayService.alipay(dto);
JSONObject
dto
=
new
JSONObject
();
dto
.
put
(
"body"
,
new
HashMap
<>());
String
payCode
=
IdGen
.
randomBase62
(
64
);
String
amount
=
"0.01"
;
dto
.
put
(
"payCode"
,
payCode
);
dto
.
put
(
"amount"
,
amount
);
dto
.
put
(
"subject"
,
"subject"
);
alipayService
.
aliPay
(
dto
);
}
public
String
aliPay
(
String
amount
,
Map
<
String
,
Object
>
body
)
{
public
String
aliPay
(
JSONObject
dto
)
throws
AlipayApiException
{
//实例化客户端
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
"https://openapi.alipay.com/gateway.do"
,
Global
.
getConfig
(
"alipay.appid"
),
Global
.
getConfig
(
"alipay.private.key"
)
,
"json"
,
"UTF-8"
,
Global
.
getConfig
(
"alipay.public.key"
),
"RSA2"
);
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
AlipayTradeAppPayRequest
request
=
new
AlipayTradeAppPayRequest
();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeAppPayModel
model
=
new
AlipayTradeAppPayModel
();
model
.
setPassbackParams
(
URLEncoder
.
encode
(
body
.
toString
()));
;
//描述信息 添加附加数据
model
.
setSubject
(
"魅格"
);
//商品标题
model
.
setOutTradeNo
(
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
).
format
(
new
Date
())+(
int
)(
Math
.
random
()*
90000
+
10000
));
//商家订单编号
model
.
setTimeoutExpress
(
"30m"
);
//超时关闭该订单时间
model
.
setTotalAmount
(
amount
);
//订单总金额
model
.
setPassbackParams
(
dto
.
get
(
"body"
).
toString
())
;
//描述信息 添加附加数据
model
.
setSubject
(
dto
.
getString
(
"subject"
)
);
//商品标题
model
.
setOutTradeNo
(
dto
.
getString
(
"payCode"
));
//商家订单编号
model
.
setTimeoutExpress
(
AlipayConfig
.
TIMEOUTEXPRESS
);
//超时关闭该订单时间
model
.
setTotalAmount
(
dto
.
getString
(
"amount"
)
);
//订单总金额
model
.
setProductCode
(
"QUICK_MSECURITY_PAY"
);
//销售产品码,商家和支付宝签约的产品码,为固定值QUICK_MSECURITY_PAY
request
.
setBizModel
(
model
);
request
.
setNotifyUrl
(
"baidu.com
"
);
//回调地址
request
.
setNotifyUrl
(
Global
.
getConfig
(
"project.access.url"
)+
"/api/pay/aliPayCallback
"
);
//回调地址
String
orderStr
=
""
;
try
{
//这里和普通的接口调用不同,使用的是sdkExecute
AlipayTradeAppPayResponse
response
=
alipayClient
.
sdkExecute
(
request
);
orderStr
=
response
.
getBody
();
System
.
out
.
println
(
orderStr
);
//就是orderString 可以直接给客户端请求,无需再做处理。
}
catch
(
AlipayApiException
e
)
{
e
.
printStackTrace
();
}
return
orderStr
;
}
}
src/main/java/com/thinkgem/jeesite/modules/pay/api/PayApiController.java
View file @
5b25274c
...
...
@@ -55,7 +55,7 @@ public class PayApiController {
try
{
PayBackDto
payBackDto
=
payService
.
quickPay
(
request
);
if
(
payBackDto
.
getUrl
()!=
null
&&
!
""
.
equals
(
payBackDto
.
getUrl
())
){
if
(
(
payBackDto
.
getUrl
()!=
null
&&
!
""
.
equals
(
payBackDto
.
getUrl
()))
||
"0"
.
equals
(
payBackDto
.
getIsUrl
())
){
resp
.
setStatus
(
ComCode
.
STATUS_CODE_2000
);
resp
.
setMessage
(
ComCode
.
STATUS_CODE_2000_DESC
);
resp
.
setData
(
payBackDto
);
...
...
@@ -79,6 +79,30 @@ public class PayApiController {
return
resp
;
}
/**
* 支付宝支付
*
* @param request
* @return
*/
@PostMapping
(
"/aliPay"
)
public
Response
aliPay
(
JuHeZhongPayRequest
request
)
{
Response
resp
=
new
Response
();
try
{
PayBackDto
payBackDto
=
payService
.
aliPay
(
request
);
resp
.
setStatus
(
ComCode
.
STATUS_CODE_2000
);
resp
.
setMessage
(
ComCode
.
STATUS_CODE_2000_DESC
);
resp
.
setData
(
payBackDto
);
}
catch
(
Exception
e
)
{
resp
.
setStatus
(
ComCode
.
STATUS_CODE_9998
);
resp
.
setMessage
(
ComCode
.
STATUS_CODE_9998_DESC
);
resp
.
setError
(
e
.
getMessage
());
e
.
printStackTrace
();
}
return
resp
;
}
/**
* 开卡
*
...
...
@@ -313,6 +337,75 @@ public class PayApiController {
}
/**
* 回调
* @param request
* @param response
*/
@RequestMapping
(
"/aliPayCallback"
)
public
void
aliPayCallback
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
System
.
out
.
println
(
"。。。。。。支付宝回调。。。。。"
);
Response
responseRetrun
=
new
Response
();
Map
map
=
request
.
getParameterMap
();
Set
keSet
=
map
.
entrySet
();
for
(
Iterator
itr
=
keSet
.
iterator
();
itr
.
hasNext
();){
Map
.
Entry
me
=(
Map
.
Entry
)
itr
.
next
();
Object
ok
=
me
.
getKey
();
//获取参数名
Object
ov
=
me
.
getValue
();
//获取参数值
System
.
out
.
println
(
ok
+
"="
+
ok
.
toString
());
System
.
out
.
println
(
ov
+
"="
+
ov
.
toString
());
String
[]
value
=
new
String
[
1
];
if
(
ov
instanceof
String
[]){
value
=(
String
[])
ov
;
}
else
{
value
[
0
]=
ov
.
toString
();
}
for
(
int
k
=
0
;
k
<
value
.
length
;
k
++){
System
.
out
.
println
(
ok
+
"="
+
value
[
k
]);
}
}
//设置编码
try
{
request
.
setCharacterEncoding
(
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
String
orderId
=
request
.
getParameter
(
"dsorderid"
);
String
code
=
request
.
getParameter
(
"respCode"
);
if
(
"00"
.
equals
(
code
)){
System
.
out
.
println
(
"orderId:"
+
orderId
);
OrderEntity
orderEntity
=
new
OrderEntity
();
orderEntity
.
setPayCode
(
orderId
);
try
{
orderEntity
=
payService
.
aliPayNotifyPay
(
orderEntity
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//返回true 收到请求,停止通知
PrintWriter
write
=
null
;
try
{
write
=
response
.
getWriter
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
write
.
print
(
"success"
);
responseRetrun
.
setMessage
(
"ok"
);
responseRetrun
.
setStatus
(
ComCode
.
STATUS_CODE_9998
);
responseRetrun
.
setData
(
orderEntity
);
write
.
flush
();
write
.
close
();
}
}
/**
* 获取支付的结果
* @param orderEntity
...
...
src/main/java/com/thinkgem/jeesite/modules/pay/juhezhong/dto/PayBackDto.java
View file @
5b25274c
...
...
@@ -10,6 +10,8 @@ public class PayBackDto {
private
String
message
;
private
String
payChannel
;
//
private
String
body
;
private
String
isUrl
=
"1"
;
// 是否是返回的url 1是 0否
public
String
getUrl
()
{
...
...
@@ -43,4 +45,12 @@ public class PayBackDto {
public
void
setIsUrl
(
String
isUrl
)
{
this
.
isUrl
=
isUrl
;
}
public
String
getBody
()
{
return
body
;
}
public
void
setBody
(
String
body
)
{
this
.
body
=
body
;
}
}
src/main/java/com/thinkgem/jeesite/modules/pay/service/PayApiService.java
View file @
5b25274c
package
com
.
thinkgem
.
jeesite
.
modules
.
pay
.
service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alipay.api.AlipayApiException
;
import
com.thinkgem.jeesite.common.baseBean.Request
;
import
com.thinkgem.jeesite.common.baseBean.Response
;
import
com.thinkgem.jeesite.common.config.Global
;
...
...
@@ -8,6 +9,7 @@ import com.thinkgem.jeesite.common.constant.ComCode;
import
com.thinkgem.jeesite.common.utils.DateUtils
;
import
com.thinkgem.jeesite.common.utils.IdGen
;
import
com.thinkgem.jeesite.modules.commonError.MyException
;
import
com.thinkgem.jeesite.modules.pay.alipay.service.AlipayService
;
import
com.thinkgem.jeesite.modules.pay.dao.PayApiDao
;
import
com.thinkgem.jeesite.modules.pay.entity.BenefitEntity
;
import
com.thinkgem.jeesite.modules.pay.entity.OrderEntity
;
...
...
@@ -22,6 +24,8 @@ import com.thinkgem.jeesite.modules.pay.juhezhong.service.JuHeZhongPayIntegralSe
import
com.thinkgem.jeesite.modules.pay.juhezhong.service.JuHeZhongPayJFenService
;
import
com.thinkgem.jeesite.modules.pay.juhezhong.service.JuHeZhongPayService
;
import
com.thinkgem.jeesite.modules.pay.juhezhong.utils.MakeOrderNum
;
import
com.thinkgem.jeesite.modules.sys.entity.Dict
;
import
com.thinkgem.jeesite.modules.sys.utils.DictUtils
;
import
com.thinkgem.jeesite.modules.user.bean.JuHeZhongPayRequest
;
import
com.thinkgem.jeesite.modules.user.bean.UserRequest
;
import
com.thinkgem.jeesite.modules.user.entity.*
;
...
...
@@ -63,6 +67,9 @@ public class PayApiService {
@Autowired
private
HuanqiuhuijuService
huanqiuhuijuService
;
@Autowired
private
AlipayService
alipayService
;
@Transactional
(
readOnly
=
false
)
public
PayBackDto
quickPay
(
JuHeZhongPayRequest
request
)
throws
MyException
,
Exception
{
if
(
ComCode
.
PAYCHANNEL_HL2
.
equals
(
request
.
getPayChannel
())){
...
...
@@ -655,6 +662,47 @@ public class PayApiService {
/**
* 支付宝支付
* @param request
* @return
* @throws AlipayApiException
*/
@Transactional
(
readOnly
=
false
)
public
PayBackDto
aliPay
(
JuHeZhongPayRequest
request
)
throws
AlipayApiException
{
// 1. 根据入参获取用户详情信息,包括支付卡片信息
UserEntity
userEntity
=
userService
.
getUserInfo
(
new
Request
(
request
.
getSubMerchantCode
()));
userEntity
=
userService
.
getUserDetailInfo
(
userEntity
);
// 2. 创建支付订单信息,并保存
String
code
=
IdGen
.
randomBase62
(
64
);
String
payNo
=
ComCode
.
YYYYMMDDHHMM
.
format
(
new
Date
())
+
IdGen
.
randomBase62
(
8
);
// 订单号
String
payCode
=
IdGen
.
randomBase62
(
64
);
DecimalFormat
df
=
new
DecimalFormat
(
"######0.00"
);
List
<
Dict
>
list
=
DictUtils
.
getDictList
(
"level_"
+
request
.
getLevel
());
String
amount
=
"398"
;
if
(
list
!=
null
&&
list
.
size
()>
0
){
amount
=
list
.
get
(
0
).
getValue
();
}
// 创建订单保存
OrderEntity
orderEntity
=
new
OrderEntity
(
code
,
request
.
getSubMerchantCode
(),
payNo
,
payCode
,
request
.
getPayMethod
(),
"ali"
,
"1"
,
amount
,
request
.
getSubject
(),
""
,
"0"
,
request
.
getCardCode
());
payDao
.
saveOrderInfo
(
orderEntity
);
// 支付宝支付返回对应支付信息
JSONObject
dto
=
new
JSONObject
();
dto
.
put
(
"payCode"
,
payCode
);
dto
.
put
(
"subject"
,
request
.
getSubject
());
dto
.
put
(
"amount"
,
amount
);
dto
.
put
(
"body"
,
new
HashMap
<>());
String
body
=
alipayService
.
aliPay
(
dto
);
PayBackDto
payBackDto
=
new
PayBackDto
();
payBackDto
.
setBody
(
body
);
return
payBackDto
;
}
/**
* 回调
* @param orderEntity
* @return
...
...
@@ -709,6 +757,26 @@ public class PayApiService {
return
orderEntity
;
}
/**
* 回调
* @param orderEntity
* @return
* @throws Exception
*/
@Transactional
(
readOnly
=
false
)
public
OrderEntity
aliPayNotifyPay
(
OrderEntity
orderEntity
)
throws
Exception
{
QuickDto
dto
=
new
QuickDto
();
orderEntity
.
setPayStatus
(
"2"
);
payDao
.
updateOrderStatus
(
orderEntity
);
orderEntity
=
payDao
.
getOrder
(
orderEntity
);
UserEntity
userEntity
=
new
UserEntity
();
userEntity
.
setCode
(
orderEntity
.
getUserCode
());
userEntity
.
setLevel
(
"D"
);
userService
.
updateUserLevel
(
userEntity
);
return
orderEntity
;
}
public
OrderEntity
getOrder
(
OrderEntity
orderEntity
){
return
payDao
.
getOrder
(
orderEntity
);
...
...
src/main/java/com/thinkgem/jeesite/modules/user/bean/JuHeZhongPayRequest.java
View file @
5b25274c
...
...
@@ -10,6 +10,8 @@ public class JuHeZhongPayRequest extends Request {
private
String
payMethod
;
//
private
String
passwd
;
// 验证码
private
String
level
;
// 升级成的等级
private
String
payNo
;
// 订单号
private
String
cvn2
;
// 安全吗
...
...
@@ -87,4 +89,12 @@ public class JuHeZhongPayRequest extends Request {
public
void
setExpireDate
(
String
expireDate
)
{
this
.
expireDate
=
expireDate
;
}
public
String
getLevel
()
{
return
level
;
}
public
void
setLevel
(
String
level
)
{
this
.
level
=
level
;
}
}
src/main/java/com/thinkgem/jeesite/modules/user/service/UserApiService.java
View file @
5b25274c
...
...
@@ -712,4 +712,8 @@ public class UserApiService {
return
userDao
.
getCardInfoByCode
(
userEntity
);
}
public
void
updateUserLevel
(
UserEntity
recommendedUser
){
userDao
.
updateUserLevel
(
recommendedUser
);
}
}
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