Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHOBUYPC
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
2
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
郝肖肖
9 years ago
Commit
3a4d45709dc6793905918b83a5b0d9ef115e9bf4
1 parent
03c54331
微信支付 回调地址改成java
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
396 additions
and
26 deletions
library/Action/WebAction.php
library/WebPlugin/Pay/Wechatqrcode/Service.php
library/WebPlugin/Pay/weixin/lib/WxPayApi.php
yohobuy/www.yohobuy.com/application/models/Shopping/Payment.php
yohobuy/www.yohobuy.com/application/modules/Pay/controllers/Payreturn.php
yohobuy/www.yohobuy.com/application/modules/Pay/controllers/Wechatqrcode.php
yohobuy/www.yohobuy.com/application/modules/Shopping/controllers/Pay.php
library/Action/WebAction.php
View file @
3a4d457
...
...
@@ -667,6 +667,22 @@ class WebAction extends Controller_Abstract
echo
"alert(
\"
{
$message
}
\"
);"
;
echo
"</script>"
;
}
if
(
$expression
===
'history.back()'
)
{
$expression
=
''
;
echo
<<<
EOF
<
script
language
=
"javascript"
>
if
(
navigator
.
userAgent
.
indexOf
(
'MSIE'
)
>=
0
&&
history
.
length
>
0
)
{
window
.
history
.
go
(
-
1
);
}
else
if
(
history
.
length
>
1
)
{
window
.
history
.
go
(
-
1
);
}
else
{
window
.
opener
=
null
;
window
.
close
();
}
</
script
>
EOF
;
}
if
(
$expression
!=
''
)
{
echo
"<script language=
\"
javascript
\"
>
\n
"
;
echo
$expression
.
"
\n
"
;
...
...
library/WebPlugin/Pay/Wechatqrcode/Service.php
View file @
3a4d457
...
...
@@ -9,6 +9,7 @@ use WebPlugin\Pay\Signature;
use
WebPlugin\Pay\weixin\lib\WxPayApi
;
use
WebPlugin\Pay\weixin\lib\WxPayOrderQuery
;
use
WebPlugin\PhpLog
;
use
WebPlugin\Helpers
;
class
Service
extends
PayAbstract
{
...
...
@@ -38,7 +39,7 @@ class Service extends PayAbstract
{
$this
->
orderCode
=
$params
->
orderCode
;
$result
=
array
(
'pay_url'
=>
$this
->
config
->
payment_url
,
'pay_url'
=>
Helpers
::
url
(
'/pay/wechatqrcode'
)
,
'pars'
=>
'order_code='
.
$this
->
orderCode
.
'&payment_code='
.
$this
->
paymentCode
,
'reqType'
=>
'get'
);
...
...
library/WebPlugin/Pay/weixin/lib/WxPayApi.php
View file @
3a4d457
...
...
@@ -542,7 +542,7 @@ class WxPayApi
curl_setopt
(
$ch
,
CURLOPT_PROXYPORT
,
WxPayConfig
::
CURL_PROXY_PORT
);
}
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYPEER
,
TRU
E
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYPEER
,
FALS
E
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYHOST
,
2
);
//严格校验
//设置header
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
FALSE
);
...
...
yohobuy/www.yohobuy.com/application/models/Shopping/Payment.php
View file @
3a4d457
...
...
@@ -15,7 +15,7 @@ use WebPlugin\Pay\weixin\lib\WxPayConfig;
use
WebPlugin\Pay\weixin\lib\WxPayNativePay
;
use
WebPlugin\Pay\weixin\lib\WxPayOrderQuery
;
use
WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder
;
use
Api\Yohobuy
;
/**
* 支付有关方法 改版
* @copyright 2016/5/22 14:19 xiaoxiao<xiaoxiao.hao@yoho.cn>
...
...
@@ -28,7 +28,194 @@ class PaymentModel
);
// 存储的UID键名
const
SESSION_UID_KEY
=
'payUserid'
;
// 是否老用户订单数判断值
const
OLD_USER_LIMIT
=
1
;
/**
* 获取支付方式选择页面有关信息
*
* @param int $uid 用户ID
* @param string $orderCode 订单号
* @return array
*/
public
static
function
getPayTypeData
(
$uid
,
$orderCode
)
{
$result
=
array
();
do
{
// 订单详情
$orderDetail
=
OrderData
::
getOrderDetail
(
$uid
,
$orderCode
);
if
(
!
$orderDetail
||
empty
(
$orderDetail
[
'data'
]))
{
$result
[
'noOrder'
]
=
true
;
break
;
}
$order
=
$orderDetail
[
'data'
];
$result
[
'orderNum'
]
=
$orderCode
;
$result
[
'count'
]
=
$order
[
'payment_amount'
];
$result
[
'paymentType'
]
=
(
$order
[
'payment_type'
]
==
1
?
'在线支付'
:
'货到付款'
);
// 货到付款的情况
if
(
$order
[
'payment_type'
]
==
2
)
{
$result
[
'finish'
]
=
true
;
// 有货币
$result
[
'yohoCoin'
]
=
$order
[
'yoho_give_coin'
];
// 订单详情链接地址
$result
[
'checkOrderUrl'
]
=
Helpers
::
url
(
'/home/orders/detail'
,
array
(
'orderCode'
=>
$orderCode
));
// 有货币地址
$result
[
'yohoCoinUrl'
]
=
Helpers
::
url
(
'/help'
,
array
(
'category_id'
=>
87
));
// vip地址
$result
[
'vipUrl'
]
=
Helpers
::
url
(
'/help'
,
array
(
'category_id'
=>
91
));
// 订单中心地址
$result
[
'ordersUrl'
]
=
Helpers
::
url
(
'/home/orders'
);
// 退换货地址
$result
[
'backGoodsUrl'
]
=
Helpers
::
url
(
'/help'
,
array
(
'category_id'
=>
121
));
// 返回首页地址
$result
[
'returnHomeUrl'
]
=
Helpers
::
url
(
'/'
);
break
;
}
$result
[
'deliveryType'
]
=
isset
(
$order
[
'delivery_time'
])
?
$order
[
'delivery_time'
]
:
''
;
//统计成交的skn
$sknList
=
array
();
$skuList
=
array
();
$goodsData
=
array
();
foreach
(
$order
[
'order_goods'
]
as
$val
)
{
$sknList
[]
=
$val
[
'product_skn'
];
$skuList
[]
=
$val
[
'product_sku'
];
$goodsData
[]
=
array
(
'goods_name'
=>
$val
[
'product_name'
],
'product_sku'
=>
$val
[
'product_sku'
],
'price'
=>
$val
[
'goods_price'
],
'number'
=>
$val
[
'buy_number'
]
);
}
$result
[
'goodsData'
]
=
$goodsData
;
// skn列表
$result
[
'sknList'
]
=
implode
(
','
,
$sknList
);
// sku列表
$result
[
'skuList'
]
=
implode
(
','
,
$skuList
);
// 用户ID
$result
[
'uid'
]
=
$uid
;
// 获取支付途径列表
$payTypes
=
PayData
::
getPaymentList
();
$defaultPayType
=
0
;
$types
=
array
();
if
(
isset
(
$payTypes
[
'data'
])
&&
!
empty
(
$payTypes
[
'data'
]))
{
$oneType
=
array
();
foreach
(
$payTypes
[
'data'
]
as
$key
=>
$payType
)
{
if
(
empty
(
$payType
[
'payIcon'
]))
{
// 排除图标不存在的支付方式
continue
;
}
// 获取第一个支付方式
if
(
$key
===
0
)
{
$defaultPayType
=
$payType
[
'id'
];
}
$oneType
=
array
();
$oneType
[
'name'
]
=
$payType
[
'payName'
];
$oneType
[
'ico'
]
=
$payType
[
'payIcon'
];
$types
[
$payType
[
'id'
]]
=
$oneType
;
}
$result
[
'list'
]
=
self
::
procPayType
(
$types
);
}
// 获取银行列表
$result
[
'entry'
]
=
self
::
procPayType
(
Banks
::
getList
(),
true
);
// 无需付款
if
(
isset
(
$order
[
"payment_amount"
])
&&
$order
[
"payment_amount"
]
==
0
)
{
// ERP提交订单状态
PayData
::
submitOrderStatus
(
$orderCode
,
0
,
''
,
''
,
0
,
''
,
''
,
''
);
// 更新订单的状态
PayData
::
updateOrderStatus
(
$order
[
'order_id'
],
$uid
,
0
,
'Y'
,
''
);
$result
[
'notNeedPay'
]
=
true
;
break
;
}
// 记录支付方式
$bankRecord
=
PayData
::
getBankByOrder
(
$orderCode
);
if
(
isset
(
$bankRecord
[
'data'
][
'bankCode'
])
&&
!
empty
(
$bankRecord
[
'data'
][
'bankCode'
]))
{
$payRecord
=
$bankRecord
[
'data'
][
'bankCode'
];
}
else
{
$payCode
=
$order
[
'payment'
]
?:
$defaultPayType
;
//记录app上的支付方式
$changeCodes
=
array
(
19
=>
21
,
// app上微信支付
22
=>
21
,
// h5微信支付
18
=>
$defaultPayType
// h5支付宝支付
);
$platformCode
=
isset
(
$changeCodes
[
$payCode
])
&&
$changeCodes
[
$payCode
]
?
$changeCodes
[
$payCode
]
:
$payCode
;
$platformCodeList
=
array_keys
(
$types
);
$payRecord
=
in_array
(
$platformCode
,
$platformCodeList
)
?
$platformCode
:
$defaultPayType
;
}
$result
[
'payRecord'
]
=
$payRecord
;
// 已完成付款的链接地址
$result
[
'ordersUrl'
]
=
Helpers
::
url
(
'/home/orders'
);
// 支付地址
$result
[
'payUrl'
]
=
Helpers
::
url
(
'/pay/index/index'
);
// 是否是老用户(用于订单统计)
$orderCount
=
0
;
//查询用户订单数接口
$orders
=
PayData
::
getOrderCountByUid
(
$uid
);
if
(
isset
(
$orders
[
'data'
])
&&
!
empty
(
$orders
[
'data'
]))
{
$orderCount
=
$orders
[
'data'
][
'total'
];
}
$result
[
'isOldUser'
]
=
(
intval
(
$orderCount
)
>
self
::
OLD_USER_LIMIT
)
?
true
:
false
;
// 订单数(用于订单统计)
$result
[
'orderCount'
]
=
$orderCount
;
$result
[
'is_advance'
]
=
$order
[
'attribute'
]
==
5
?
'Y'
:
'N'
;
// 订单商品(用于订单统计)
$result
[
'orderGoods'
]
=
$order
[
'order_goods'
];
// 订单商品数(用于订单统计)
$result
[
'ordersGoodsNums'
]
=
count
(
$order
[
'order_goods'
]);
}
while
(
false
);
return
$result
;
}
/**
* 处理支付类型数据
*
* @param array $pays 支付方式数据
* @param bool $isBank 是否是银行数据
* @return array
*/
private
static
function
procPayType
(
$pays
,
$isBank
=
false
)
{
$result
=
array
();
$onePay
=
array
();
foreach
(
$pays
as
$code
=>
$pay
)
{
$onePay
=
array
();
$onePay
[
'dataId'
]
=
$code
;
$onePay
[
'dataVal'
]
=
$isBank
?
'12_'
.
$code
:
$code
.
'_platform'
;
$onePay
[
'idNum'
]
=
$code
;
$onePay
[
'ico'
]
=
$pay
[
'ico'
];
$onePay
[
'name'
]
=
$pay
[
'name'
];
$onePay
[
'imgId'
]
=
$onePay
[
'dataVal'
];
$result
[]
=
$onePay
;
}
return
$result
;
}
/**
* 支付成功处理方法
* @param type object $payResult 支付成功返回对象
* @return type []
*/
public
static
function
procOrderData
(
$payResult
)
{
do
{
...
...
@@ -37,12 +224,8 @@ class PaymentModel
break
;
}
$orderCode
=
$payResult
->
orderCode
;
$uid
=
''
;
if
(
USE_CACHE
)
{
// 通过订单号,从缓存记录中获取uid
$uid
=
Cache
::
get
(
self
::
SESSION_UID_KEY
.
$orderCode
);
}
$orderInfo
=
OrderData
::
getOrderDetail
(
$uid
,
$payResult
->
orderCode
);
$uid
=
self
::
getUid
(
$orderCode
);
$orderInfo
=
OrderData
::
getOrderDetail
(
$uid
,
$orderCode
);
if
(
empty
(
$orderInfo
[
'data'
]))
{
self
::
$code
[
'message'
]
=
'未查到订单信息,订单状态更新失败!'
;
break
;
...
...
@@ -93,4 +276,142 @@ class PaymentModel
return
self
::
$code
;
}
/**
* 处理微信支付
*
* @param int $uid 用户ID
* @param string $orderCode 订单号
* @return array
*/
public
static
function
weixinQrcode
(
$orderCode
)
{
do
{
if
(
empty
(
$orderCode
))
{
self
::
$code
[
'message'
]
=
'订单号不能为空'
;
break
;
}
$uid
=
self
::
getUid
(
$orderCode
);
/* 判断订单信息是否存在 */
$orderDetail
=
OrderData
::
getOrderDetail
(
$uid
,
$orderCode
);
if
(
empty
(
$orderDetail
[
'data'
]))
{
self
::
$code
[
'message'
]
=
'没有找到该订单'
;
break
;
}
if
(
$orderDetail
[
'data'
][
'is_cancel'
]
===
'Y'
)
{
self
::
$code
[
'message'
]
=
'该订单已被取消'
;
break
;
}
if
(
$orderDetail
[
'data'
][
'payment_status'
]
===
'Y'
)
{
self
::
$code
[
'message'
]
=
'该订单已付款,不需要再次付款'
;
break
;
}
//统一下单
$totalFee
=
strval
(
$orderDetail
[
'data'
][
'payment_amount'
]
*
100
);
$input
=
new
WxPayUnifiedOrder
();
$input
->
SetBody
(
'有货订单号:'
.
$orderCode
);
$input
->
SetOut_trade_no
(
'YOHOBuy_'
.
$orderCode
);
// 商户订单号
$input
->
SetTotal_fee
(
$totalFee
);
$input
->
SetTime_start
(
date
(
"YmdHis"
));
$input
->
SetTime_expire
(
date
(
"YmdHis"
,
time
()
+
600
));
$input
->
SetNotify_url
(
Yohobuy
::
SERVICE_URL
.
'payment/weixin_notify'
);
$input
->
SetTrade_type
(
"NATIVE"
);
$input
->
SetProduct_id
(
$orderCode
);
$notify
=
new
WxPayNativePay
();
$payResult
=
$notify
->
GetPayUrl
(
$input
);
// if ($payResult['result_code'] === 'FAIL') {
// self::$code['message'] = $payResult['err_code_des'];
// break;
// }
$orderData
=
$orderDetail
[
'data'
];
$firstGoods
=
current
(
$orderData
[
'order_goods'
]);
self
::
$code
=
array
(
'code'
=>
200
,
'message'
=>
'支付成功,请等待发货'
,
'orderNum'
=>
$orderData
[
'order_code'
],
'amount'
=>
$orderData
[
'payment_amount'
],
'address'
=>
$orderData
[
'address'
],
'name'
=>
$orderData
[
'user_name'
],
'tellphoneNum'
=>
$orderData
[
'mobile'
],
'tradeName'
=>
$firstGoods
[
'product_name'
],
'choosePayUrl'
=>
Helpers
::
url
(
'/shopping/pay'
,
array
(
'order_code'
=>
$orderData
[
'order_code'
])),
'qrcodeUrl'
=>
isset
(
$payResult
[
'code_url'
])
?
$payResult
[
'code_url'
]
:
''
// 'http://paysdk.weixin.qq.com/example/qrcode.php?data=' . $result['code_url']
);
}
while
(
false
);
return
self
::
$code
;
}
/**
* 轮询查询--检查微信扫码支付结果
*
* @param int $uid 用户ID
* @param int $orderCode 订单号
* @return array 订单支付结果
*/
public
static
function
checkWechatPayStatus
(
$orderCode
)
{
do
{
if
(
empty
(
$orderCode
))
{
self
::
$code
[
'message'
]
=
'未查询到订单号'
;
break
;
}
// 组装微信支付的订单号
$tradeNo
=
'YOHOBuy_'
.
$orderCode
;
$input
=
new
WxPayOrderQuery
();
$input
->
SetOut_trade_no
(
$tradeNo
);
$payResult
=
WxPayApi
::
orderQuery
(
$input
);
if
(
isset
(
$payResult
[
'trade_state'
])
&&
$payResult
[
'trade_state'
]
===
'SUCCESS'
)
{
self
::
$code
=
array
(
'code'
=>
'200'
,
'message'
=>
'success'
);
}
}
while
(
false
);
return
self
::
$code
;
}
/**
* 根据支付ID获取支付相关参数
*
* @param int $payId 支付ID
* @return array
*/
public
static
function
getPaymentById
(
$payId
)
{
$result
=
array
();
$paymentParams
=
PayData
::
getPaymentById
(
$payId
);
if
(
isset
(
$paymentParams
[
'data'
])
&&
!
empty
(
$paymentParams
[
'data'
]))
{
$result
=
array
(
'id'
=>
$payId
,
'pay_code'
=>
$paymentParams
[
'data'
][
'payCode'
],
'pay_params'
=>
isset
(
$paymentParams
[
'data'
][
'payParams'
])
?
$paymentParams
[
'data'
][
'payParams'
]
:
''
);
}
return
$result
;
}
/**
* 通过订单号,从缓存记录中获取uid
* @param type string $orderCode 订单号
* @return type int
*/
private
static
function
getUid
(
$orderCode
)
{
$uid
=
''
;
if
(
USE_CACHE
)
{
// 通过订单号,从缓存记录中获取uid
$uid
=
Cache
::
get
(
self
::
SESSION_UID_KEY
.
$orderCode
);
}
return
$uid
;
}
}
\ No newline at end of file
...
...
yohobuy/www.yohobuy.com/application/modules/Pay/controllers/Payreturn.php
View file @
3a4d457
<?php
use
Action\WebAction
;
use
Shopping\PayModel
;
use
Shopping\PaymentModel
;
use
WebPlugin\Pay\PayFactory
;
use
WebPlugin\Pay\Rspparams
;
...
...
@@ -11,23 +10,58 @@ use WebPlugin\Pay\Rspparams;
*/
class
PayreturnController
extends
WebAction
{
public
function
init
()
{
parent
::
init
();
}
/**
* 支付宝浏览器端返回
*/
public
function
alipayreturnAction
()
{
$payment
=
PayModel
::
getPaymentById
(
2
);
$payment
=
Pay
ment
Model
::
getPaymentById
(
2
);
$payService
=
PayFactory
::
factory
(
$payment
);
$res
=
$payService
->
parseResponse
(
$_GET
);
$dealResult
=
$this
->
payResultProc
(
$res
,
2
);
$dealResult
[
'payData'
]
=
array
(
'payWay'
=>
'支付宝'
);
$this
->
commonShowResult
(
$dealResult
);
}
/**
* 微信支付-轮询--jsonPcallback响应订单支付状态
*/
public
function
wechatcallbackAction
()
{
$callback
=
$this
->
get
(
'callback'
);
$orderCode
=
$this
->
get
(
'ordercode'
);
$response
=
PaymentModel
::
checkWechatPayStatus
(
$orderCode
);
$this
->
helpJsonCallbackResult
(
$callback
,
$response
[
'code'
],
$response
[
'message'
]);
}
/**
* 微信扫码支付返回
*/
public
function
wechatqrcodereturnAction
()
{
$dealResult
=
array
(
'code'
=>
500
,
'message'
=>
'支付失败'
);
do
{
$orderCode
=
$this
->
get
(
'order_code'
,
0
);
if
(
empty
(
$orderCode
))
{
break
;
}
$payment
=
PaymentModel
::
getPaymentById
(
21
);
$payService
=
PayFactory
::
factory
(
$payment
);
$res
=
$payService
->
parseResponse
(
array
(
'orderCode'
=>
$orderCode
));
$dealResult
=
$this
->
payResultProc
(
$res
,
21
);
$dealResult
[
'payData'
]
=
array
(
'payWay'
=>
'微信扫码支付'
);
}
while
(
false
);
$this
->
commonShowResult
(
$dealResult
);
}
/**
* 通用显示结果的方法
* @param array $dealResult
...
...
yohobuy/www.yohobuy.com/application/modules/Pay/controllers/Wechatqrcode.php
View file @
3a4d457
<?php
use
Action\WebAction
;
use
Shopping\PayModel
;
use
Shopping\Pay
ment
Model
;
use
WebPlugin\Helpers
;
class
WechatqrcodeController
extends
WebAction
...
...
@@ -13,22 +13,20 @@ class WechatqrcodeController extends WebAction
*/
public
function
indexAction
()
{
$uid
=
$this
->
getUid
(
true
);
if
(
!
$uid
)
{
$this
->
go
(
Helpers
::
url
(
'/signin.html'
,
array
(
'refer'
=>
$this
->
server
(
'HTTP_REFERER'
))));
}
$this
->
autoLogin
();
$orderCode
=
$this
->
get
(
'order_code'
,
$this
->
get
(
'ordercode'
));
$data
=
PayModel
::
weixinQrcode
(
$uid
,
$orderCode
);
if
(
isset
(
$data
[
'error'
]))
{
$data
=
PaymentModel
::
weixinQrcode
(
$orderCode
);
if
(
empty
(
$data
[
'code'
])
||
$data
[
'code'
]
!==
200
)
{
$this
->
helpJsRedirect
(
$data
[
'message'
]);
}
$this
->
setSimpleHeader
();
// 轮询是否支付成功地址
$data
[
'payHost'
]
=
Helpers
::
url
(
'/pay/
notice
/wechatcallback'
,
array
(
'ordercode'
=>
$orderCode
));
$data
[
'payHost'
]
=
Helpers
::
url
(
'/pay/
payreturn
/wechatcallback'
,
array
(
'ordercode'
=>
$orderCode
));
// 支付成功跳转地址
$data
[
'paySuccessUrl'
]
=
Helpers
::
url
(
'/pay/notice/wechatqrcodereturn'
,
array
(
'order_code'
=>
$orderCode
));
$data
[
'paySuccessUrl'
]
=
Helpers
::
url
(
'/pay/payreturn/wechatqrcodereturn'
,
array
(
'order_code'
=>
$orderCode
));
$this
->
_view
->
display
(
'index'
,
array
(
'wechatqrcode'
=>
$data
,
'wechatqrcodePage'
=>
true
...
...
yohobuy/www.yohobuy.com/application/modules/Shopping/controllers/Pay.php
View file @
3a4d457
<?php
use
Action\WebAction
;
use
Shopping\PayModel
;
use
Shopping\Pay
ment
Model
;
use
WebPlugin\Helpers
;
use
LibModels\Web\Home\UserData
;
use
WebPlugin\Cache
;
...
...
@@ -45,7 +45,7 @@ class PayController extends WebAction
$this
->
go
(
Helpers
::
url
(
'/pay/index/index'
,
array
(
'order_code'
=>
$orderCode
,
'payment_type'
=>
'2_platform'
)));
}
$data
=
PayModel
::
getPayTypeData
(
$uid
,
$orderCode
);
$data
=
Pay
ment
Model
::
getPayTypeData
(
$uid
,
$orderCode
);
//不存在订单时
if
(
isset
(
$data
[
'noOrder'
]))
{
$this
->
helpJsRedirect
(
'没有找到该订单'
);
...
...
Please
register
or
login
to post a comment