|
@@ -4,20 +4,13 @@ Dever::apply('sdk/alipay', 'pay');
|
|
|
|
|
|
class Alipay extends Core
|
|
|
{
|
|
|
+ private $signType = 'RSA2';
|
|
|
public function __construct($config)
|
|
|
{
|
|
|
$project = Dever::project('pay');
|
|
|
- $this->config = new \Cmbc\Setting();
|
|
|
# 通知接口
|
|
|
$config['notify'] = $this->url($config['type'], $config['id']);
|
|
|
- # 证书
|
|
|
- $config['ssl'] = array
|
|
|
- (
|
|
|
- 'cert' => $config['file_cert'],
|
|
|
- 'key' => $config['file_key'],
|
|
|
- );
|
|
|
-
|
|
|
- $this->config->set($config['appid'], $config['appsecret'], $config['mchid'], $config['notify'], $config['key'], $config['ssl'], $config['type'], $config['timeout']);
|
|
|
+ $this->config = $config;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -25,23 +18,44 @@ class Alipay extends Core
|
|
|
*/
|
|
|
public function notify()
|
|
|
{
|
|
|
- $input = file_get_contents("php://input");
|
|
|
- if ($input) {
|
|
|
- parse_str($input, $input);
|
|
|
- } else {
|
|
|
- $input = Dever::input();
|
|
|
- }
|
|
|
- $this->log('支付回调-初始化', $input);
|
|
|
-
|
|
|
- $tools = new \Cmbc\Handle();
|
|
|
- $callback = $tools->get('notify', $this->config);
|
|
|
- $result = $callback->request($input, $this);
|
|
|
- if ($result) {
|
|
|
- $this->log('支付回调-获取数据', $result);
|
|
|
- $this->updateOrder($result['mhtOrderNo'], $result['mhtOrderAmt']);
|
|
|
- echo 'success=Y';die;
|
|
|
+ $type = Dever::input('type');
|
|
|
+ if ($type == 1) {
|
|
|
+ $input = $_GET;
|
|
|
+ unset($input['account_id']);
|
|
|
+ $result = $this->check($input);
|
|
|
+ if ($result) {
|
|
|
+ $status = 1;
|
|
|
+ } else {
|
|
|
+ $status = 2;
|
|
|
+ }
|
|
|
+ $refer = Dever::input('refer');
|
|
|
+ $refer = urldecode($refer) . '&status=' . $status;
|
|
|
+ Dever::location($refer);
|
|
|
} else {
|
|
|
- echo 'success=N';die;
|
|
|
+ $input = $_POST;
|
|
|
+ if (!$input) {
|
|
|
+ echo 'fail';die;
|
|
|
+ }
|
|
|
+ unset($input['account_id']);
|
|
|
+ $this->log('支付回调-初始化', $input);
|
|
|
+
|
|
|
+ $result = $this->check($input);
|
|
|
+
|
|
|
+ if ($result) {
|
|
|
+ $this->log('支付回调-获取数据', $result);
|
|
|
+
|
|
|
+ if($input['trade_status'] == 'TRADE_FINISHED') {
|
|
|
+ #退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
|
|
|
+ $this->updateOrder($result['out_trade_no'], $result['total_amount'], '已超过退款期限');
|
|
|
+ } elseif ($input['trade_status'] == 'TRADE_SUCCESS') {
|
|
|
+ #付款完成后,支付宝系统发送该交易状态通知
|
|
|
+ $this->updateOrder($result['out_trade_no'], $result['total_amount']);
|
|
|
+ }
|
|
|
+
|
|
|
+ echo 'success';die;
|
|
|
+ } else {
|
|
|
+ echo 'fail';die;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -51,27 +65,41 @@ class Alipay extends Core
|
|
|
public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false)
|
|
|
{
|
|
|
$trade_type = $this->getType($type);
|
|
|
- $order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config->GetType(), $order_id);
|
|
|
+ $order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config['type'], $order_id);
|
|
|
|
|
|
- $tools = new \Cmbc\Handle();
|
|
|
+ $aop = new \AopClient();
|
|
|
|
|
|
- $order = $tools->get('order', $this->config);
|
|
|
-
|
|
|
- $request['mhtOrderNo'] = $order_id;
|
|
|
- $request['mhtOrderName'] = $name;
|
|
|
- $request['mhtOrderAmt'] = $cash * 100;
|
|
|
- $request['mhtOrderDetail'] = $name;
|
|
|
- $request['mhtOrderStartTime'] = date("YmdHis");
|
|
|
- $request['notifyUrl'] = $this->config->getNotifyUrl();
|
|
|
- $request['outputType'] = 1;
|
|
|
- if (!$openid) {
|
|
|
- $request['consumerId'] = 'ofBUV0RUoy_8C4VctZjrSDGzhUfY';
|
|
|
- } else {
|
|
|
- $request['consumerId'] = $openid;
|
|
|
+ $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
|
|
+ if ($this->config['box'] == 2) {
|
|
|
+ $aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
|
|
|
}
|
|
|
|
|
|
- $result = $order->request($request);
|
|
|
- $this->updateOrderParam($order_id, $result);
|
|
|
+ $aop->appId = $this->config['appid'];
|
|
|
+ $aop->rsaPrivateKey = $this->config['private_key'];
|
|
|
+ $aop->alipayrsaPublicKey = $this->config['public_key'];
|
|
|
+ $aop->signType = $this->signType;
|
|
|
+ // 开启页面信息输出
|
|
|
+ $aop->debugInfo = true;
|
|
|
+
|
|
|
+ $request['out_trade_no'] = $order_id;
|
|
|
+ $request['body'] = $name;
|
|
|
+ $request['total_amount'] = $cash;
|
|
|
+ $request['subject'] = $name;
|
|
|
+ $request['timeout_express'] = $this->config['timeout'];
|
|
|
+ $content = json_encode($request, JSON_UNESCAPED_UNICODE);
|
|
|
+
|
|
|
+ $request = new \AlipayTradeWapPayRequest();
|
|
|
+
|
|
|
+ $request->setNotifyUrl($this->config['notify']);
|
|
|
+ $request->setReturnUrl($this->config['refer']);
|
|
|
+ $request->setBizContent($content);
|
|
|
+
|
|
|
+ if ($type == 1) {
|
|
|
+ $result = $aop->pageExecute($request, 'post');
|
|
|
+ } else {
|
|
|
+ $result = $aop->Execute($request);
|
|
|
+ }
|
|
|
+
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
@@ -92,13 +120,6 @@ class Alipay extends Core
|
|
|
public function applet($order)
|
|
|
{
|
|
|
$result = array();
|
|
|
- if (isset($order['prepay_id'])) {
|
|
|
- $result['time'] = $order['timeStamp'];
|
|
|
- $result['nonce_str'] = $order['nonceStr'];
|
|
|
- $result['prepay_id'] = $order['prepay_id'];
|
|
|
- $result['sign_type'] = $order['signType'];
|
|
|
- $result['sign'] = $order['paySign'];
|
|
|
- }
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
@@ -108,45 +129,7 @@ class Alipay extends Core
|
|
|
*/
|
|
|
public function page($order, $refer)
|
|
|
{
|
|
|
- $refer = urldecode($refer);
|
|
|
- $tools = new \JsApiPay($this->config);
|
|
|
- $info = $tools->GetJsApiParameters($order);
|
|
|
-
|
|
|
- $html = '<script type="text/javascript">
|
|
|
- function jsApiCall()
|
|
|
- {
|
|
|
- WeixinJSBridge.invoke(
|
|
|
- "getBrandWCPayRequest",
|
|
|
- '.$info.',
|
|
|
- function(res){
|
|
|
- //WeixinJSBridge.log(res.err_msg);
|
|
|
- if(res.err_msg == "get_brand_wcpay_request:ok")
|
|
|
- {
|
|
|
- location.href = "'.$refer.'";
|
|
|
- } else {
|
|
|
- alert(res.err_code+res.err_desc+res.err_msg);
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- function callpay()
|
|
|
- {
|
|
|
- if (typeof WeixinJSBridge == "undefined"){
|
|
|
- if( document.addEventListener ){
|
|
|
- document.addEventListener("WeixinJSBridgeReady", jsApiCall, false);
|
|
|
- }else if (document.attachEvent){
|
|
|
- document.attachEvent("WeixinJSBridgeReady", jsApiCall);
|
|
|
- document.attachEvent("onWeixinJSBridgeReady", jsApiCall);
|
|
|
- }
|
|
|
- }else{
|
|
|
- jsApiCall();
|
|
|
- }
|
|
|
- }
|
|
|
- callpay();
|
|
|
- </script>';
|
|
|
-
|
|
|
- return $html;
|
|
|
+ return $order;
|
|
|
}
|
|
|
|
|
|
private function getType($type)
|
|
@@ -163,4 +146,12 @@ class Alipay extends Core
|
|
|
|
|
|
return $type;
|
|
|
}
|
|
|
+
|
|
|
+ private function check($data)
|
|
|
+ {
|
|
|
+ $aop = new \AopClient();
|
|
|
+ $aop->alipayrsaPublicKey = $this->config['public_key'];
|
|
|
+ $result = $aop->rsaCheckV1($data, $this->config['public_key'], $this->signType);
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
}
|