|
|
<?php
|
|
|
/**
|
|
|
* 支付宝即使到账接口
|
|
|
* @author Yunliang
|
|
|
*/
|
|
|
Zc::import('@.vendor.alipay.lib.alipay_require_inc');
|
|
|
|
|
|
class Alipay {
|
|
|
|
|
|
/**
|
|
|
* @var RechargeService
|
|
|
*/
|
|
|
private $rechargeSerivice;
|
|
|
|
|
|
/**
|
|
|
* @var BanWordsService
|
|
|
*/
|
|
|
private $banWordsService;
|
|
|
|
|
|
private $smsLog;
|
|
|
|
|
|
private $scanLog;
|
|
|
|
|
|
public function __construct() {
|
|
|
$this->rechargeSerivice = Zc::singleton('RechargeService');
|
|
|
$this->banWordsService = Zc::singleton('BanWordsService');
|
|
|
|
|
|
$this->smsLog = Zc::getLog('user/recharge/sms');
|
|
|
$this->scanLog = Zc::getLog('user/recharge/scan');
|
|
|
}
|
|
|
|
|
|
public function smsPay($venderId, $amount, $smsNum, $notes, $return, $notify) {
|
|
|
$this->smsLog->info("Alipay->smsPay: venderId $venderId, amount $amount, smsNum $smsNum, notes $notes, return $return, notify $notify");
|
|
|
|
|
|
$smsRechargeOrderUuid = $this->rechargeSerivice->addSmsRechargeOrder($venderId, $amount, $smsNum, $notes);
|
|
|
|
|
|
$this->smsLog->info("venderId $venderId, smsRechargeOrderUuid $smsRechargeOrderUuid");
|
|
|
if(!empty($smsRechargeOrderUuid)) {
|
|
|
$subject = sprintf(Zc::C('appChineseName') . '短信充值:%d条短信,%s元', $smsNum, $amount);
|
|
|
$outTradeNo = CommonTool::buildRechargeOutTradeNo(RechargeConst::smsRechargeOrderOutTradeNoPrefix, $smsRechargeOrderUuid);
|
|
|
$html = $this->pay($outTradeNo, $amount, $notify, $return, $subject, $notes);
|
|
|
}
|
|
|
return $html;
|
|
|
}
|
|
|
|
|
|
public function pay($tradeNo, $amount, $notify, $return, $subject, $notes) {
|
|
|
$alipayConfig = $this->getAlipayConfig();
|
|
|
|
|
|
$parameter = array (
|
|
|
"service" => 'create_direct_pay_by_user',
|
|
|
"partner" => $alipayConfig['partner'],
|
|
|
"payment_type" => "1",
|
|
|
"notify_url" => $notify,
|
|
|
"return_url" => $return,
|
|
|
"seller_email" => $alipayConfig['seller_email'],
|
|
|
"out_trade_no" => $tradeNo,
|
|
|
"subject" => $subject,
|
|
|
"total_fee" => $amount,
|
|
|
"body" => $notes,
|
|
|
"show_url" => "",
|
|
|
"anti_phishing_key" => "",
|
|
|
"exter_invoke_ip" => $_SERVER['REMOTE_ADDR'],
|
|
|
"_input_charset" => strtolower('utf-8')
|
|
|
);
|
|
|
|
|
|
$alipaySubmit = new AlipaySubmit($alipayConfig);
|
|
|
$html = $alipaySubmit->buildRequestForm($parameter, "get");
|
|
|
|
|
|
return $html;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付宝return的校验
|
|
|
*/
|
|
|
public function verifyReturn() {
|
|
|
// 计算得出通知验证结果
|
|
|
$route = $_GET['route'];
|
|
|
unset($_GET['route']);
|
|
|
|
|
|
$alipayConfig = $this->getAlipayConfig();
|
|
|
$alipayNotify = new AlipayNotify($alipayConfig);
|
|
|
$verifyResult = $alipayNotify->verifyReturn();
|
|
|
|
|
|
$_GET['route'] = $route;
|
|
|
return $verifyResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付宝return的校验
|
|
|
*/
|
|
|
public function verifyNotify() {
|
|
|
// 计算得出通知验证结果
|
|
|
$alipayConfig = $this->getAlipayConfig();
|
|
|
$alipayNotify = new AlipayNotify($alipayConfig);
|
|
|
$verify_result = $alipayNotify->verifyNotify();
|
|
|
return $verify_result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取支付宝的支付配置
|
|
|
*/
|
|
|
private function getAlipayConfig() {
|
|
|
if (Zc::C('isSzChengji')) {
|
|
|
$partner = '2088231567929400';
|
|
|
$sellerEmail = 'szchengjiinc@foxmail.com';
|
|
|
$key = 'otzsvs68i1vfsrzesqt6k9k0jkcwqcjf';
|
|
|
} else {
|
|
|
$partner = '2088712203114939';
|
|
|
$sellerEmail = 'chengjiinc@foxmail.com';
|
|
|
$key = 'jb3fj2izwb6mm8sldlfyjwn1hb3am88t';
|
|
|
}
|
|
|
|
|
|
if (AppConst::isPddDzApp()) {
|
|
|
$partner = '2088712081222171';
|
|
|
$sellerEmail = 'tang895@foxmail.com';
|
|
|
$key = '1oc99s6hs3v4dkh1h3x21fuo8veljvli';
|
|
|
}
|
|
|
|
|
|
$alipayConfig = array(
|
|
|
'partner' => $partner,
|
|
|
'seller_email' => $sellerEmail,
|
|
|
'key' => $key,
|
|
|
'sign_type' => strtoupper('MD5'),
|
|
|
'input_charset' => strtolower('utf-8'),
|
|
|
'cacert' => Zc::C(ZcConfigConst::DirFsLibs) . 'vendor/alipay/alipaycacert.pem',
|
|
|
'transport' => 'http'
|
|
|
);
|
|
|
return $alipayConfig;
|
|
|
}
|
|
|
|
|
|
private function redirect($url, $status = 302) {
|
|
|
header('Location: ' . str_replace(array('&', "\n", "\r"), array('&', '', ''), $url), true, $status);
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
public function pictureScanPay($mallId, $taskId, $notes, $return, $notify){
|
|
|
$this->scanLog->info("Alipay->pictureScanPay: venderId {$mallId}, notes {$notes}, tradeNo {$taskId}, return {$return}, notify {$notify}");
|
|
|
$startRet = $this->banWordsService->startScanTaskPay($mallId, $taskId);
|
|
|
if(CommonTool::isFailRet($startRet)){
|
|
|
$this->redirect(Zc::url(RouteConst::detectBanWordsIndex));
|
|
|
}
|
|
|
$payAmont = $startRet['payAmount'];
|
|
|
$rechargeOrderId = $startRet['rechargeOrderId'];
|
|
|
$scanCountNum = $startRet['scanCountNum'];
|
|
|
|
|
|
$subject = sprintf('%s图片扫描充值:%d张图片,共%s元', Zc::C('appChineseName'), $scanCountNum, $payAmont);
|
|
|
$this->scanLog->info("mallId $mallId, recharegeOrderId {$rechargeOrderId}");
|
|
|
if((int)$rechargeOrderId <= 0) {
|
|
|
$this->redirect(Zc::url(RouteConst::detectBanWordsIndex));
|
|
|
}
|
|
|
|
|
|
$tradeNo = CommonTool::buildRechargeOutTradeNo(RechargeConst::pspOutTradeNoPrefix, $rechargeOrderId);
|
|
|
$html = $this->pay($tradeNo, $payAmont, $notify, $return, $subject, $notes);
|
|
|
|
|
|
echo $html;
|
|
|
}
|
|
|
}
|