Commit 25444040 authored by xiabin's avatar xiabin

添加支付宝支付的return url

parent 8ed28c17
...@@ -99,7 +99,7 @@ class JsApiPay ...@@ -99,7 +99,7 @@ class JsApiPay
//初始化curl //初始化curl
$ch = curl_init(); $ch = curl_init();
//设置超时 //设置超时
curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout); curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
......
...@@ -477,44 +477,6 @@ class HomeController extends \yii\web\Controller ...@@ -477,44 +477,6 @@ class HomeController extends \yii\web\Controller
return QrCode::jpg(urldecode($url)); return QrCode::jpg(urldecode($url));
} }
/**
* 移动端微信支付
*/
public
function actionMobilePay()
{
$weixinpay = \Yii::$app->params['weixinpay'];
$client = new Client(
[
'timeout' => 8,
'verify' => FALSE,
'connect_timeout' => 8
]
);
$order_id = '12312312323';
$uri = WeixinPay::UNIFIEDORDER;
$xml = [
'appid' => $weixinpay['appid'],
'mch_id' => $weixinpay['mchid'],
'device_info' => "WEB",
'nonce_str' => Yii::$app->security->generateRandomString(16),
'sign' => '',
'body' => '最课堂 - 课程购买',
'out_trade_no' => $order_id,
'total_fee' => 1,
'spbill_create_ip' => $_SERVER['SERVER_ADDR'],
'notify_url' => WeixinPay::NOTIFY_URL,
'trade_type' => 'MWEB',
];
$xml['sign'] = WeixinPay::makeWeixinPaySign($xml, $weixinpay['key']);
$xml = Utils::assocArrayToXML('xml', $xml);
$reponse = $client->request('POST', $uri, ['Content - Type' => 'text / xml; charset = UTF8', 'body' => $xml]);
$reponse = $reponse->getBody();
$result = ((string)$reponse);
$result = Utils::xmlToArray($result);
var_dump($result);
}
/** /**
* 生成订单号 * 生成订单号
......
...@@ -188,7 +188,7 @@ class PayController extends Controller ...@@ -188,7 +188,7 @@ class PayController extends Controller
'sign' => '', 'sign' => '',
'body' => '最课堂-课程购买', 'body' => '最课堂-课程购买',
'out_trade_no' => $order_id, 'out_trade_no' => $order_id,
'total_fee' => $order->price, 'total_fee' => $order->credit * 100,
'spbill_create_ip' => $_SERVER['SERVER_ADDR'], 'spbill_create_ip' => $_SERVER['SERVER_ADDR'],
'notify_url' => WeixinPay::NOTIFY_URL, 'notify_url' => WeixinPay::NOTIFY_URL,
'trade_type' => 'NATIVE', 'trade_type' => 'NATIVE',
......
...@@ -2,39 +2,26 @@ ...@@ -2,39 +2,26 @@
//error_reporting(E_ERROR); //error_reporting(E_ERROR);
use common\libs\WeixinPay; use common\libs\WeixinPay;
require_once dirname(dirname(dirname(dirname(__FILE__))))."/common/libs/weixin/libs/WxPay.Api.php"; require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/common/libs/weixin/libs/WxPay.Api.php";
require_once dirname(dirname(dirname(dirname(__FILE__))))."/common/libs/weixin/WxPay.JsApiPay.php"; require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/common/libs/weixin/WxPay.JsApiPay.php";
//打印输出数组信息
function printf_info($data)
{
foreach ($data as $key => $value) {
echo "<font color='#00ff55;'>$key</font> : $value <br/>";
}
}
//①、获取用户openid //①、获取用户openid
$tools = new JsApiPay(); $tools = new JsApiPay();
$openId = $tools->GetOpenid(); $openId = $tools->GetOpenid();
//②、统一下单 //②、统一下单
$input = new WxPayUnifiedOrder(); $input = new WxPayUnifiedOrder();
$input->SetBody("最课堂-课程购买"); $input->SetBody("最课堂-课程购买");
$input->SetOut_trade_no($number); $input->SetOut_trade_no($number);
$input->SetTotal_fee($price); $input->SetTotal_fee($price * 100);
$input->SetTime_start(date("YmdHis")); $input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetNotify_url(WeixinPay::NOTIFY_URL); $input->SetNotify_url(WeixinPay::NOTIFY_URL);
$input->SetTrade_type("JSAPI"); $input->SetTrade_type("JSAPI");
$input->SetOpenid($openId); $input->SetOpenid($openId);
$order = WxPayApi::unifiedOrder($input); $order = WxPayApi::unifiedOrder($input);
echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
printf_info($order);
$jsApiParameters = $tools->GetJsApiParameters($order); $jsApiParameters = $tools->GetJsApiParameters($order);
//获取共享收货地址js函数参数
$editAddress = $tools->GetEditAddressParameters();
//③、在支持成功回调通知中处理成功之后的事宜,见 notify.php //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
/** /**
...@@ -76,42 +63,10 @@ $editAddress = $tools->GetEditAddressParameters(); ...@@ -76,42 +63,10 @@ $editAddress = $tools->GetEditAddressParameters();
} }
} }
</script> </script>
<script type="text/javascript">
//获取共享地址
function editAddress() {
WeixinJSBridge.invoke(
'editAddress',
<?php echo $editAddress; ?>,
function (res) {
var value1 = res.proviceFirstStageName;
var value2 = res.addressCitySecondStageName;
var value3 = res.addressCountiesThirdStageName;
var value4 = res.addressDetailInfo;
var tel = res.telNumber;
alert(value1 + value2 + value3 + value4 + ":" + tel);
}
);
}
window.onload = function () {
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', editAddress, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', editAddress);
document.attachEvent('onWeixinJSBridgeReady', editAddress);
}
} else {
editAddress();
}
};
</script>
</head> </head>
<body> <body>
<br/> <br/>
<font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px"><?=$price?></span</b></font><br/><br/> <font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px"><?= $price ?></span</b></font><br/><br/>
<div align="center"> <div align="center">
<button <button
style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;"
......
...@@ -184,7 +184,7 @@ ...@@ -184,7 +184,7 @@
window.location.href = url; window.location.href = url;
}, },
weixinJsPay(courseId){ weixinJsPay(courseId){
var url = __BASE_URL__ + '/weixin-js-pay/index?courseId=' + courseId; var url = __BASE_URL__ + 'weixin-js-pay/index?courseId=' + courseId;
window.location.href = url; window.location.href = url;
}, },
login(){ login(){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment