Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
a6e149fd
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
18
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a6e149fd
编写于
7月 19, 2017
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支付宝支付调整
上级
1618f38e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
171 deletion
+61
-171
app/appfront/modules/Payment/controllers/alipay/StandardController.php
...modules/Payment/controllers/alipay/StandardController.php
+18
-74
app/apphtml5/modules/Payment/controllers/alipay/StandardController.php
...modules/Payment/controllers/alipay/StandardController.php
+13
-74
services/payment/Alipay.php
services/payment/Alipay.php
+30
-23
未找到文件。
app/appfront/modules/Payment/controllers/alipay/StandardController.php
浏览文件 @
a6e149fd
...
...
@@ -20,7 +20,10 @@ class StandardController extends AppfrontController
{
public
$enableCsrfValidation
=
false
;
/**
* 在网站下单页面,选择支付宝支付方式后,
* 跳转到支付宝支付页面前准备的部分。
*/
public
function
actionStart
()
{
//$AopSdkFile = Yii::getAlias('@fecshop/lib/alipay/AopSdk.php');
...
...
@@ -29,19 +32,23 @@ class StandardController extends AppfrontController
return
Yii
::
$service
->
payment
->
alipay
->
start
();
}
// 2.Review 从paypal确认后返回
/**
* 从支付宝支付成功后,跳转返回 fec-shop 的部分
*/
public
function
actionReview
()
{
Yii
::
$service
->
payment
->
alipay
->
review
();
//$trade_no = Yii::$app->request->get('trade_no');
//$out_trade_no = Yii::$app->request->get('out_trade_no');
//if($trade_no && $out_trade_no){
// echo Yii::$service->payment->alipay->review($trade_no,$out_trade_no);
//}
$reviewStatus
=
Yii
::
$service
->
payment
->
alipay
->
review
();
if
(
$reviewStatus
){
$successRedirectUrl
=
Yii
::
$service
->
payment
->
getStandardSuccessRedirectUrl
();
return
Yii
::
$service
->
url
->
redirect
(
$successRedirectUrl
);
}
else
{
echo
Yii
::
$service
->
helper
->
errors
->
get
(
'<br/>'
);
return
;
}
}
/**
* IPN,支付宝消息接收部分
*/
public
function
actionIpn
()
{
\
Yii
::
info
(
'alipay ipn begin'
,
'fecshop_debug'
);
...
...
@@ -80,67 +87,4 @@ class StandardController extends AppfrontController
}
*/
/*
public $enableCsrfValidation = false;
private $use_local_certs = true;
public function actionStart()
{
Yii::$service->page->theme->layoutFile = 'blank.php';
$data = $this->getBlock()->getLastData();
if (is_array($data) && !empty($data)) {
return $this->render($this->action->id, $data);
} else {
return Yii::$service->url->redirectByUrlKey('checkout/onepage');
}
}
public function actionIpn()
{
\Yii::info('paypal ipn begin', 'fecshop_debug');
$post = Yii::$app->request->post();
if (is_array($post) && !empty($post)) {
$post = \Yii::$service->helper->htmlEncode($post);
ob_start();
ob_implicit_flush(false);
var_dump($post);
$post_log = ob_get_clean();
\Yii::info($post_log, 'fecshop_debug');
//Yii::$service->payment->paypal->receiveIpn($post);
}
}
public function actionTest()
{
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?invoice=1000000124&first_name=test&discount=7.11&mc_shipping=0.00&mc_currency=EUR&payer_status=verified&shipping_discount=0.00&payment_fee=&address_status=unconfirmed&payment_gross=&settle_currency=USD&address_zip=212121&address_country_code=FR&txn_type=cart&num_cart_items=3&mc_handling=0.00&verify_sign=AuRlNZvMOhdn8iDWY5YoMB9iRTDzAZppqkxKbGiGEUvmwrFAdvscLpXK&payer_id=FKL4V7D5GCACY&option_selection2_1=L&option_selection2_2=L&charset=windows-1252&tax1=0.00&receiver_id=H4KXD885J8LV2&tax2=0.00&tax3=0.00&mc_handling1=0.00&mc_handling2=0.00&mc_handling3=0.00&item_name1=Reindeer+Pattern+Glitter+Christmas+Dress&tax=0.00&item_name2=Sweet+Polka+Dot+Open+Back+Summer+Dress+For+Women&item_name3=fast_shipping&payment_type=instant&mc_shipping1=0.00&address_street=2121%0D%0A23232&mc_shipping2=0.00&mc_shipping3=0.00&txn_id=9NN80505PR451120Y&exchange_rate=1.29364&mc_gross_1=40.34&quantity1=2&mc_gross_2=30.69&quantity2=1&item_number1=22221&protection_eligibility=Eligible&mc_gross_3=18.51&quantity3=1&item_number2=sk0003&item_number3=Fast+Shipping%28+5-10+work+days%29&custom=&option_selection1_1=black&option_selection1_2=red&business=zqy234api1-facilitator%40126.com&residence_country=US&last_name=facilitator&address_state=Hautes-Alpes&payer_business_name=test+facilitator%27s+Test+Store&payer_email=zqy234api1-facilitator-1%40126.com&option_name2_1=My+size&option_name2_2=size&settle_amount=103.09&address_city=2121&payment_status=Completed&payment_date=22%3A40%3A06+Feb+20%2C+2017+PST&transaction_subject=&receiver_email=zqy234api1-facilitator%40126.com&mc_fee=2.74¬ify_version=3.8&shipping_method=Default&address_country=France&mc_gross=82.43&test_ipn=1&insurance_amount=0.00&address_name=1111+22&option_name1_1=My+color&option_name1_2=color&ipn_track_id=26d73da3782c3&cmd=_notify-validate';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// This is often required if the server is missing a global cert bundle, or is using an outdated one.
if ($this->use_local_certs) {
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cert/cacert.pem');
}
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']);
$res = curl_exec($ch);
echo $res;
}
*/
}
app/apphtml5/modules/Payment/controllers/alipay/StandardController.php
浏览文件 @
a6e149fd
...
...
@@ -21,31 +21,33 @@ class StandardController extends AppfrontController
public
$enableCsrfValidation
=
false
;
/**
*
在网站下单页面,选择支付宝支付方式后,
*
跳转到支付宝支付页面前准备的部分。
*
在网站下单页面,选择支付宝支付方式后,
*
跳转到支付宝支付页面前准备的部分。
*/
public
function
actionStart
()
{
//$AopSdkFile = Yii::getAlias('@fecshop/lib/alipay/AopSdk.php');
//require($AopSdkFile);
echo
'
支付宝支付跳转中
...'
;
echo
'
支付宝支付跳转中...'
;
return
Yii
::
$service
->
payment
->
alipay
->
start
();
}
/**
*
从支付宝支付成功后,跳转返回 fec-shop 的部分
*
从支付宝支付成功后,跳转返回 fec-shop 的部分
*/
public
function
actionReview
()
{
Yii
::
$service
->
payment
->
alipay
->
review
();
//$trade_no = Yii::$app->request->get('trade_no');
//$out_trade_no = Yii::$app->request->get('out_trade_no');
//if($trade_no && $out_trade_no){
// echo Yii::$service->payment->alipay->review($trade_no,$out_trade_no);
//}
$reviewStatus
=
Yii
::
$service
->
payment
->
alipay
->
review
();
if
(
$reviewStatus
){
$successRedirectUrl
=
Yii
::
$service
->
payment
->
getStandardSuccessRedirectUrl
();
return
Yii
::
$service
->
url
->
redirect
(
$successRedirectUrl
);
}
else
{
echo
Yii
::
$service
->
helper
->
errors
->
get
(
'<br/>'
);
return
;
}
}
/**
* IPN
,支付宝消息接收部分
* IPN
,支付宝消息接收部分
*/
public
function
actionIpn
()
{
...
...
@@ -85,67 +87,4 @@ class StandardController extends AppfrontController
}
*/
/*
public $enableCsrfValidation = false;
private $use_local_certs = true;
public function actionStart()
{
Yii::$service->page->theme->layoutFile = 'blank.php';
$data = $this->getBlock()->getLastData();
if (is_array($data) && !empty($data)) {
return $this->render($this->action->id, $data);
} else {
return Yii::$service->url->redirectByUrlKey('checkout/onepage');
}
}
public function actionIpn()
{
\Yii::info('paypal ipn begin', 'fecshop_debug');
$post = Yii::$app->request->post();
if (is_array($post) && !empty($post)) {
$post = \Yii::$service->helper->htmlEncode($post);
ob_start();
ob_implicit_flush(false);
var_dump($post);
$post_log = ob_get_clean();
\Yii::info($post_log, 'fecshop_debug');
//Yii::$service->payment->paypal->receiveIpn($post);
}
}
public function actionTest()
{
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?invoice=1000000124&first_name=test&discount=7.11&mc_shipping=0.00&mc_currency=EUR&payer_status=verified&shipping_discount=0.00&payment_fee=&address_status=unconfirmed&payment_gross=&settle_currency=USD&address_zip=212121&address_country_code=FR&txn_type=cart&num_cart_items=3&mc_handling=0.00&verify_sign=AuRlNZvMOhdn8iDWY5YoMB9iRTDzAZppqkxKbGiGEUvmwrFAdvscLpXK&payer_id=FKL4V7D5GCACY&option_selection2_1=L&option_selection2_2=L&charset=windows-1252&tax1=0.00&receiver_id=H4KXD885J8LV2&tax2=0.00&tax3=0.00&mc_handling1=0.00&mc_handling2=0.00&mc_handling3=0.00&item_name1=Reindeer+Pattern+Glitter+Christmas+Dress&tax=0.00&item_name2=Sweet+Polka+Dot+Open+Back+Summer+Dress+For+Women&item_name3=fast_shipping&payment_type=instant&mc_shipping1=0.00&address_street=2121%0D%0A23232&mc_shipping2=0.00&mc_shipping3=0.00&txn_id=9NN80505PR451120Y&exchange_rate=1.29364&mc_gross_1=40.34&quantity1=2&mc_gross_2=30.69&quantity2=1&item_number1=22221&protection_eligibility=Eligible&mc_gross_3=18.51&quantity3=1&item_number2=sk0003&item_number3=Fast+Shipping%28+5-10+work+days%29&custom=&option_selection1_1=black&option_selection1_2=red&business=zqy234api1-facilitator%40126.com&residence_country=US&last_name=facilitator&address_state=Hautes-Alpes&payer_business_name=test+facilitator%27s+Test+Store&payer_email=zqy234api1-facilitator-1%40126.com&option_name2_1=My+size&option_name2_2=size&settle_amount=103.09&address_city=2121&payment_status=Completed&payment_date=22%3A40%3A06+Feb+20%2C+2017+PST&transaction_subject=&receiver_email=zqy234api1-facilitator%40126.com&mc_fee=2.74¬ify_version=3.8&shipping_method=Default&address_country=France&mc_gross=82.43&test_ipn=1&insurance_amount=0.00&address_name=1111+22&option_name1_1=My+color&option_name1_2=color&ipn_track_id=26d73da3782c3&cmd=_notify-validate';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// This is often required if the server is missing a global cert bundle, or is using an outdated one.
if ($this->use_local_certs) {
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cert/cacert.pem');
}
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']);
$res = curl_exec($ch);
echo $res;
}
*/
}
services/payment/Alipay.php
浏览文件 @
a6e149fd
...
...
@@ -62,7 +62,8 @@ class Alipay extends Service
/**
* 初始化 $this->_AopClient
*/
protected
function
initParam
(){
protected
function
initParam
()
{
if
(
!
$this
->
_AopClient
){
$this
->
_AopClient
=
new
\
AopClient
;
$this
->
_AopClient
->
gatewayUrl
=
$this
->
gatewayUrl
;
...
...
@@ -91,7 +92,8 @@ class Alipay extends Service
* 在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,
* 支付宝才会认定为买家付款成功。
*/
protected
function
validateReviewOrder
(
$out_trade_no
,
$total_amount
,
$seller_id
,
$auth_app_id
){
protected
function
validateReviewOrder
(
$out_trade_no
,
$total_amount
,
$seller_id
,
$auth_app_id
)
{
if
(
!
$this
->
_order
){
$this
->
_order
=
Yii
::
$service
->
order
->
getByIncrementId
(
$out_trade_no
);
Yii
::
$service
->
payment
->
setPaymentMethod
(
$this
->
_order
[
'payment_method'
]);
...
...
@@ -130,7 +132,8 @@ class Alipay extends Service
* 支付宝 支付成功后,返回网站,调用该函数进行支付宝订单支付状态查询
* 如果支付成功,则修改订单状态为支付成功状态。
*/
protected
function
actionReview
(){
protected
function
actionReview
()
{
$this
->
initParam
();
$trade_no
=
Yii
::
$app
->
request
->
get
(
'trade_no'
);
$out_trade_no
=
Yii
::
$app
->
request
->
get
(
'out_trade_no'
);
...
...
@@ -138,7 +141,7 @@ class Alipay extends Service
$seller_id
=
Yii
::
$app
->
request
->
get
(
'seller_id'
);
$auth_app_id
=
Yii
::
$app
->
request
->
get
(
'auth_app_id'
);
//验证订单的合法性
if
(
!
$this
->
validateReviewOrder
(
$out_trade_no
,
$total_amount
,
$seller_id
,
$auth_app_id
)){
if
(
!
$this
->
validateReviewOrder
(
$out_trade_no
,
$total_amount
,
$seller_id
,
$auth_app_id
)){
return
false
;
}
...
...
@@ -153,17 +156,16 @@ class Alipay extends Service
$result
=
$this
->
_AopClient
->
execute
(
$this
->
_alipayRequest
);
$responseNode
=
str_replace
(
"."
,
"_"
,
$this
->
_alipayRequest
->
getApiMethodName
())
.
"_response"
;
$resultCode
=
$result
->
$responseNode
->
code
;
if
(
!
empty
(
$resultCode
)
&&
$resultCode
==
10000
)
{
$this
->
paymentSuccess
(
$out_trade_no
,
$trade_no
,
false
);
if
(
!
empty
(
$resultCode
)
&&
$resultCode
==
10000
)
{
$this
->
paymentSuccess
(
$out_trade_no
,
$trade_no
);
// 清空购物车
Yii
::
$service
->
cart
->
clearCartProductAndCoupon
();
// 跳转 success_redirect_url
$successRedirectUrl
=
Yii
::
$service
->
payment
->
getStandardSuccessRedirectUrl
();
//echo $successRedirectUrl;exit;
return
Yii
::
$service
->
url
->
redirect
(
$successRedirectUrl
);
return
true
;
}
else
{
echo
'resultCode:'
.
$resultCode
.
"<br/>"
;
echo
"alipay payment fail"
;
Yii
::
$service
->
helper
->
errors
->
add
(
'alipay payment fail,resultCode:'
.
$resultCode
);
return
false
;
}
}
...
...
@@ -172,14 +174,15 @@ class Alipay extends Service
* 您开启log后,可以在@app/runtime/fecshop_logs
* 文件夹下执行:tail -f fecshop_debug.log , 来查看log输出。
*/
public
function
receiveIpn
(){
public
function
receiveIpn
()
{
Yii
::
info
(
'alipay service receiveIpn():begin init param'
,
'fecshop_debug'
);
$this
->
initParam
();
Yii
::
info
(
'alipay service receiveIpn():begin rsaCheck'
,
'fecshop_debug'
);
// 验签
$checkV2Status
=
$this
->
_AopClient
->
rsaCheckV1
(
$_POST
,
''
,
$this
->
signType
);
Yii
::
info
(
'alipay service receiveIpn():rsacheck end'
,
'fecshop_debug'
);
if
(
$checkV2Status
)
{
if
(
$checkV2Status
)
{
Yii
::
info
(
'alipay service receiveIpn():rsacheck success'
,
'fecshop_debug'
);
$trade_no
=
Yii
::
$app
->
request
->
post
(
'trade_no'
);
$out_trade_no
=
Yii
::
$app
->
request
->
post
(
'out_trade_no'
);
...
...
@@ -195,14 +198,15 @@ class Alipay extends Service
Yii
::
info
(
'alipay service receiveIpn(): [ trade_status: ]'
.
$trade_status
,
'fecshop_debug'
);
//验证订单的合法性
if
(
!
$this
->
validateReviewOrder
(
$out_trade_no
,
$total_amount
,
$seller_id
,
$auth_app_id
))
{
if
(
!
$this
->
validateReviewOrder
(
$out_trade_no
,
$total_amount
,
$seller_id
,
$auth_app_id
))
{
Yii
::
info
(
'alipay service receiveIpn(): validate order fail'
,
'fecshop_debug'
);
return
false
;
}
Yii
::
info
(
'alipay service receiveIpn():validate order success'
,
'fecshop_debug'
);
if
(
self
::
TRADE_SUCCESS
==
$trade_status
){
if
(
self
::
TRADE_SUCCESS
==
$trade_status
){
Yii
::
info
(
'alipay service receiveIpn():alipay trade success '
,
'fecshop_debug'
);
if
(
$this
->
paymentSuccess
(
$out_trade_no
,
$trade_no
)){
if
(
$this
->
paymentSuccess
(
$out_trade_no
,
$trade_no
)){
Yii
::
info
(
'alipay service receiveIpn():update order status success'
,
'fecshop_debug'
);
return
true
;
...
...
@@ -214,7 +218,6 @@ class Alipay extends Service
}
}
/**
* @property $increment_id | String 订单号
* @property $sendEmail | boolean 是否发送邮件
...
...
@@ -222,12 +225,17 @@ class Alipay extends Service
*/
protected
function
paymentSuccess
(
$increment_id
,
$trade_no
,
$sendEmail
=
true
)
{
if
(
!
$this
->
_order
)
{
if
(
!
$this
->
_order
)
{
$this
->
_order
=
Yii
::
$service
->
order
->
getByIncrementId
(
$increment_id
);
Yii
::
$service
->
payment
->
setPaymentMethod
(
$this
->
_order
[
'payment_method'
]);
}
// 如果订单状态已经是processing,那么,不需要更改订单状态了。
if
(
$this
->
_order
[
'order_status'
]
==
Yii
::
$service
->
order
->
payment_status_processing
){
return
true
;
}
$order
=
$this
->
_order
;
if
(
isset
(
$order
[
'increment_id'
])
&&
$order
[
'increment_id'
])
{
if
(
isset
(
$order
[
'increment_id'
])
&&
$order
[
'increment_id'
])
{
// 如果支付成功,则更改订单状态为支付成功
$order
->
order_status
=
Yii
::
$service
->
order
->
payment_status_processing
;
$order
->
txn_id
=
$trade_no
;
// 支付宝的交易号
...
...
@@ -236,9 +244,8 @@ class Alipay extends Service
// 得到当前的订单信息
$orderInfo
=
Yii
::
$service
->
order
->
getOrderInfoByIncrementId
(
$order
[
'increment_id'
]);
// 发送新订单邮件
if
(
$sendEmail
){
Yii
::
$service
->
email
->
order
->
sendCreateEmail
(
$orderInfo
);
}
Yii
::
$service
->
email
->
order
->
sendCreateEmail
(
$orderInfo
);
return
true
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录