public function pay($runValidation = true)
{
if ($runValidation && !$this->validate()) {
return false;
}
if ($this->_order->status !== Order::STATUS_UNPAID) {
return false;
}
try {
switch ($this->platform) {
case self::PLATFORM_ALIPAY:
require_once Yii::getAlias('@vendor') . '/payment/alipay/alipay.config.php';
require_once Yii::getAlias('@vendor') . '/payment/alipay/lib/alipay_submit.class.php';
$parameter = ['service' => 'create_direct_pay_by_user', 'partner' => trim($alipay_config['partner']), 'seller_email' => trim($alipay_config['seller_email']), 'payment_type' => '1', 'notify_url' => Url::to(['/payment/alipay-order-notify'], true), 'return_url' => Url::to(['/payment/alipay-order-return'], true), 'out_trade_no' => $this->_order->order_sn, 'subject' => '订单支付', 'total_fee' => $this->_order->real_fee, 'body' => '笑e购(xiaoego.com)订单,订单号:' . $this->_order->order_sn, 'show_url' => Url::to(['/order/detail', 'order' => $this->_order->order_sn], true), 'anti_phishing_key' => '', 'exter_invoke_ip' => '', '_input_charset' => trim(strtolower($alipay_config['input_charset']))];
//建立请求
$alipaySubmit = new \AlipaySubmit($alipay_config);
$htmlText = $alipaySubmit->buildRequestForm($parameter, 'post', '');
break;
default:
throw new InvalidValueException();
}
return $htmlText;
} catch (\Exception $e) {
return false;
}
}