예제 #1
0
 public function aliPay()
 {
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         exit;
     }
     if (!isset($_POST['sign']) || !isset($_POST['sign_type']) || $_POST['sign_type'] != 'RSA') {
         echo 'fail';
         exit;
     }
     $ret = AliSDK::verifySign($_POST, CONFIG_PATH . '/alipay/alipay_public_key.pem', $_POST['sign']);
     $ret = true;
     // TODO
     if ($ret === false) {
         Log::pay('ali wap pay notify fail (sign fail) ' . json_encode($_POST, JSON_UNESCAPED_UNICODE));
         echo 'success';
         exit;
     }
     if (!empty($_POST['notify_id'])) {
         $ret = AliSDK::verifyNotify(ALI_PAY_PARTNER_ID, CONFIG_PATH . '/alipay/cacert.pem', $_POST['notify_id']);
         if ($ret === false) {
             Log::pay('ali wap pay notify fail (verify notify_id fail) ' . json_encode($_POST, JSON_UNESCAPED_UNICODE));
             echo 'fail';
             exit;
         }
     }
     $nk = Nosql::NK_PAY_NOTIFY_DE_DUPLICATION . $data['out_trade_no'];
     $nk = Nosql::get($nk);
     if (!empty($nk)) {
         Log::pay('ali wap pay notify success (had handled): ' . json_encode($_POST, JSON_UNESCAPED_UNICODE));
         echo 'success';
         return;
     }
     if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
         if ($this->onPayNotifyOk($_POST['out_trade_no'], $_POST['total_fee'], $_POST['total_fee']) === true) {
             Nosql::setex($nk, Nosql::NK_PAY_NOTIFY_DE_DUPLICATION_EXPIRE, 'x');
             Log::pay('ali wap pay notify success : ' . json_encode($_POST, JSON_UNESCAPED_UNICODE));
             echo 'success';
             return;
         }
     } else {
         // TRADE_FINISHED WAIT_BUYER_PAY 不处理
         echo 'success';
         return;
     }
     echo 'fail';
 }