Authored by whb

Merge branch 'temp'

... ... @@ -604,4 +604,29 @@ class WebAction extends Controller_Abstract
return $apiDomain;
}
/**
* JS 跳转并提示
*
* @param String $message 提示信息
* @param String $expression 附加的JS
* @return void
*/
protected function helpJsRedirect($message = '', $expression = "history.back()")
{
header("content-type: text/html; charset=utf-8");
if ($message != '') {
$message = strtr(addslashes($message), array('\n' => '\\n'));
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
if ($expression != '') {
echo "<script language=\"javascript\">\n";
echo $expression . "\n";
echo "</script>";
}
exit();
}
}
... ...
... ... @@ -5,78 +5,87 @@ namespace WebPlugin\Pay\Alibank;
class Config
{
var $pay_url = "https://mapi.alipay.com/gateway.do";
/**
* 服务名,即时到帐为create_direct_pay_by_user
* Enter description here ...
* @var String
*/
var $service = "create_direct_pay_by_user";
/**
* 合作伙伴在支付宝的用户ID
* Enter description here ...
* @var string
*/
var $partner = "";
/**
* 编码
* Enter description here ...
* @var String
*/
var $input_charset = "utf-8";
/**
* 通知url,(用于后台提交)
* Enter description here ...
* @var String
*/
var $notify_url = "notice/alibanknotice";
/**
* 浏览器的返回
* Enter description here ...
* @var string
*/
var $return_url = "notice/alibankreturn";
/**
* 签名方式
* Enter description here ...
* @var String
*/
var $sign_type = "MD5";
/**
* 支付类型,1为购买
* Enter description here ...
* @var Integer
*/
var $payment_type = "1";
/**
* Key
* Enter description here ...
* @var String
*/
var $alipay_key = "";
/**
* 销售者mail
* Enter description here ...
* @var String
*/
var $sellerMail = "";
/**
* 防钓鱼配置
*/
var $anti_fishing = array(
'ip_enable' => false,
'timestamp_enable' =>false
);
var $pay_url = "https://mapi.alipay.com/gateway.do";
/**
* 服务名,即时到帐为create_direct_pay_by_user
* Enter description here ...
* @var String
*/
var $service = "create_direct_pay_by_user";
/**
* 合作伙伴在支付宝的用户ID
* Enter description here ...
* @var string
*/
var $partner = "";
/**
* 编码
* Enter description here ...
* @var String
*/
var $input_charset = "utf-8";
/**
* 通知url,(用于后台提交)
* Enter description here ...
* @var String
*/
var $notify_url = "notice/alibanknotice";
/**
* 浏览器的返回
* Enter description here ...
* @var string
*/
var $return_url = "notice/alibankreturn";
/**
* 签名方式
* Enter description here ...
* @var String
*/
var $sign_type = "MD5";
/**
* 支付类型,1为购买
* Enter description here ...
* @var Integer
*/
var $payment_type = "1";
/**
* Key
* Enter description here ...
* @var String
*/
var $alipay_key = "";
/**
* 销售者mail
* Enter description here ...
* @var String
*/
var $sellerMail = "";
/**
* 防钓鱼配置
*/
var $anti_fishing = array(
'ip_enable' => false,
'timestamp_enable' => false
);
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/alibank';
/**
* @var int 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
... ...
... ... @@ -6,10 +6,12 @@ use DOMDocument;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
class Service extends PayAbstract
{
var $config ;
public $config;
private $log;
public function __construct(array $paymentParams)
{
... ... @@ -19,6 +21,8 @@ class Service extends PayAbstract
$this->config->partner = $myConfig->merchant_id;
$this->config->alipay_key = $myConfig->merchant_key;
$this->config->sellerMail = $myConfig->merchant_other_code;
$this->log = new PhpLog($this->config->logDir, "PRC", $this->config->logLevel);
}
/**
... ... @@ -106,12 +110,17 @@ class Service extends PayAbstract
/* 返回示例
* http://www.yohobuy.com/pay/notice/alipayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR&notify_time=2011-06-11+07%3A48%3A10&notify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5
*/
$this->log->LogInfo("===开始解析支付宝银行的回调参数===");
$this->log->logInfo("-----回调参数为---");
$this->log->logInfo(var_export($arrResponse));
if(isset($arrResponse['q'])){
unset($arrResponse['q']);
}
$rsp = new Rspparams();
if(!$this->checkResponse($arrResponse))
{
$this->log->LogInfo("验证支付宝银行的回调参数失败");
//验证不成功
$rsp->payResult = -1;
}
... ...
... ... @@ -4,81 +4,90 @@ namespace WebPlugin\Pay\Alipay;
class Config
{
//老网关,2013年3月20日下线
//老网关,2013年3月20日下线
// var $pay_url = "https://www.alipay.com/cooperate/gateway.do";
//新网关
var $pay_url = "https://mapi.alipay.com/gateway.do";
/**
* 服务名,即时到帐为create_direct_pay_by_user
* Enter description here ...
* @var String
*/
var $service = "create_direct_pay_by_user";
/**
* 合作伙伴在支付宝的用户ID
* Enter description here ...
* @var string
*/
var $partner = "";
/**
* 编码
* Enter description here ...
* @var String
*/
var $input_charset = "utf-8";
/**
* 通知url,(用于后台提交)
* Enter description here ...
* @var String
*/
var $notify_url = "notice/alipaynotice";
/**
* 浏览器的返回
* Enter description here ...
* @var string
*/
var $return_url = "notice/alipayreturn";
/**
* 签名方式
* Enter description here ...
* @var String
*/
var $sign_type = "MD5";
/**
* 支付类型,1为购买
* Enter description here ...
* @var Integer
*/
var $payment_type = "1";
/**
* Key
* Enter description here ...
* @var String
*/
var $alipay_key = "";
/**
* 销售者mail
* Enter description here ...
* @var String
*/
var $sellerMail = "";
/**
* 防钓鱼配置
*/
var $anti_fishing = array(
'ip_enable' => false,
'timestamp_enable' =>false
);
//新网关
var $pay_url = "https://mapi.alipay.com/gateway.do";
/**
* 服务名,即时到帐为create_direct_pay_by_user
* Enter description here ...
* @var String
*/
var $service = "create_direct_pay_by_user";
/**
* 合作伙伴在支付宝的用户ID
* Enter description here ...
* @var string
*/
var $partner = "";
/**
* 编码
* Enter description here ...
* @var String
*/
var $input_charset = "utf-8";
/**
* 通知url,(用于后台提交)
* Enter description here ...
* @var String
*/
var $notify_url = "notice/alipaynotice";
/**
* 浏览器的返回
* Enter description here ...
* @var string
*/
var $return_url = "notice/alipayreturn";
/**
* 签名方式
* Enter description here ...
* @var String
*/
var $sign_type = "MD5";
/**
* 支付类型,1为购买
* Enter description here ...
* @var Integer
*/
var $payment_type = "1";
/**
* Key
* Enter description here ...
* @var String
*/
var $alipay_key = "";
/**
* 销售者mail
* Enter description here ...
* @var String
*/
var $sellerMail = "";
/**
* 防钓鱼配置
*/
var $anti_fishing = array(
'ip_enable' => false,
'timestamp_enable' => false
);
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/alibank';
/**
* @var string 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
\ No newline at end of file
... ...
... ... @@ -5,26 +5,31 @@ namespace WebPlugin\Pay\Alipay;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
class Service extends PayAbstract
{
var $config ;
public function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'alipay';
$this->config = new Config();
$myConfig = json_decode($paymentParams["pay_params"]) ;
$this->config->partner = $myConfig->merchant_id;
$this->config->alipay_key = $myConfig->merchant_key;
$this->config->sellerMail = $myConfig->merchant_other_code;
}
/**
* 获取时间戳
*/
private function getTimestamp() {
public $config;
private $log;
public function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'alipay';
$this->config = new Config();
$myConfig = json_decode($paymentParams["pay_params"]);
$this->config->partner = $myConfig->merchant_id;
$this->config->alipay_key = $myConfig->merchant_key;
$this->config->sellerMail = $myConfig->merchant_other_code;
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
/**
* 获取时间戳
*/
private function getTimestamp()
{
$url = "https://mapi.alipay.com/gateway.do?service=query_timestamp&partner=" . trim(strtolower($this->config->partner)) . "&_input_charset=" . trim(strtolower($this->config->input_charset));
$doc = new DOMDocument();
... ... @@ -33,152 +38,155 @@ class Service extends PayAbstract
$encrypt_key = $itemEncrypt_key->item(0)->nodeValue;
return $encrypt_key;
}
}
/**
* @param Reqparams $params
* @return array
*/
public function getPayRequestPars(Reqparams $params)
{
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
{
$this->log->LogInfo("===开始处理支付宝的请求参数===");
$this->log->logInfo("-----请求参数为---");
$this->log->logInfo(var_export($params));
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
// $loseTime = intval(($params->orderTime + 7200 -time())/60);
// $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60); //第二天十点
$parameter = array(
'service' => $this->config->service,
'partner' => $this->config->partner,
'_input_charset' => $this->config->input_charset,
'notify_url' => $baseUrl . $this->config->notify_url,
'return_url' => $baseUrl . $this->config->return_url,
$parameter = array(
'service' => $this->config->service,
'partner' => $this->config->partner,
'_input_charset' => $this->config->input_charset,
'notify_url' => $baseUrl . $this->config->notify_url,
'return_url' => $baseUrl . $this->config->return_url,
/* 业务参数 */
'subject' => $params->goodsName,
'out_trade_no' => $params->orderCode,
'subject' => $params->goodsName,
'out_trade_no' => $params->orderCode,
// 'it_b_pay' => $loseTime . 'm',
'total_fee' => $params->totalFee / 100, //单位为元
'payment_type' => $this->config->payment_type,
'seller_email' => $this->config->sellerMail,
'sign_id_ext' =>$params->uid,
'sign_name_ext' => $params->userName
'total_fee' => $params->totalFee / 100, //单位为元
'payment_type' => $this->config->payment_type,
'seller_email' => $this->config->sellerMail,
'sign_id_ext' => $params->uid,
'sign_name_ext' => $params->userName
);
if($this->config->anti_fishing['timestamp_enable']) {
$anti_phishing_key = $this->getTimestamp();
if(!empty($anti_phishing_key)) {
$parameter['anti_phishing_key'] = $anti_phishing_key;
}
}
if($this->config->anti_fishing['ip_enable']) {
$parameter['exter_invoke_ip'] = $params->spbill_create_ip;
}
if(!empty($params->paymentParameter)){
//使用快捷支付
$parameter['token'] = $params->paymentParameter;
if ($this->config->anti_fishing['timestamp_enable']) {
$anti_phishing_key = $this->getTimestamp();
if (!empty($anti_phishing_key)) {
$parameter['anti_phishing_key'] = $anti_phishing_key;
}
}
if ($this->config->anti_fishing['ip_enable']) {
$parameter['exter_invoke_ip'] = $params->spbill_create_ip;
}
if (!empty($params->paymentParameter)) {
//使用快捷支付
$parameter['token'] = $params->paymentParameter;
}
ksort($parameter);
reset($parameter);
$param = '';
$sign = '';
foreach ($parameter AS $key => $val)
{
$param .= "$key=" .urlencode($val). "&";
$sign .= "$key=$val&";
}
$param = '';
$sign = '';
foreach ($parameter AS $key => $val) {
$param .= "$key=" . urlencode($val) . "&";
$sign .= "$key=$val&";
}
$param = substr($param, 0, -1);
$sign = substr($sign, 0, -1). $this->config->alipay_key;
$result = array(
'pay_url' => $this->config->pay_url,
'pars' => $param . "&sign=" . md5($sign). "&sign_type=" . $this->config-> sign_type,
'reqType' => 'get'
);
return $result;
}
public function parseResponse(array $arrResponse)
{
/* 返回示例
* http://www.yohobuy.com/pay/notice/alipayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR&notify_time=2011-06-11+07%3A48%3A10&notify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5
*/
if(isset($arrResponse['q'])){
unset($arrResponse['q']);
}
$rsp = new Rspparams();
if(!$this->checkResponse($arrResponse))
{
//验证不成功
$rsp->payResult = -1;
}
else
{
$rsp->bankName = "";
$outTradeNo = $arrResponse["out_trade_no"];
$rsp->orderCode = $outTradeNo;
$rsp->payResult = $this->convertResult($arrResponse["trade_status"]);
$rsp->payTime = isset($arrResponse["gmt_payment"]) ? $arrResponse["gmt_payment"] : '';
$rsp->totalFee = $arrResponse["total_fee"];
$rsp->resultMsg = $arrResponse["notify_type"];
//添加支付订单号和交易号
$rsp->payOrderCode = $outTradeNo;
$rsp->tradeNo = $arrResponse['trade_no'];
$rsp->bankBillNo = "";
}
return $rsp;
}
protected function convertResult($resultCode)
{
if($resultCode == "TRADE_SUCCESS")
{
return 200;
}
return 400;
}
/**
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
private function paraFilter($para) {
$para_filter = array();
foreach ($para as $key=>$val) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
/**
* 对数组排序
* @param $para 排序前的数组
* return 排序后的数组
*/
private function argSort($para) {
ksort($para);
reset($para);
return $para;
}
/**
* 验证回复的正确性
* @see QPay_Utils_Abstract::verifResponse()
*/
protected function checkResponse(array $arrResponse)
{
ksort($arrResponse);
$sign = substr($sign, 0, -1) . $this->config->alipay_key;
$result = array(
'pay_url' => $this->config->pay_url,
'pars' => $param . "&sign=" . md5($sign) . "&sign_type=" . $this->config->sign_type,
'reqType' => 'get'
);
return $result;
}
public function parseResponse(array $arrResponse)
{
/* 返回示例
* http://www.yohobuy.com/pay/notice/alipayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR&notify_time=2011-06-11+07%3A48%3A10&notify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5
*/
$this->log->LogInfo("===开始解析支付宝的回调参数===");
$this->log->logInfo("-----回调参数为---");
$this->log->logInfo(var_export($arrResponse));
if (isset($arrResponse['q'])) {
unset($arrResponse['q']);
}
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
//验证不成功
$rsp->payResult = -1;
} else {
$rsp->bankName = "";
$outTradeNo = $arrResponse["out_trade_no"];
$rsp->orderCode = $outTradeNo;
$rsp->payResult = $this->convertResult($arrResponse["trade_status"]);
$rsp->payTime = isset($arrResponse["gmt_payment"]) ? $arrResponse["gmt_payment"] : '';
$rsp->totalFee = $arrResponse["total_fee"];
$rsp->resultMsg = $arrResponse["notify_type"];
//添加支付订单号和交易号
$rsp->payOrderCode = $outTradeNo;
$rsp->tradeNo = $arrResponse['trade_no'];
$rsp->bankBillNo = "";
}
return $rsp;
}
protected function convertResult($resultCode)
{
if ($resultCode == "TRADE_SUCCESS") {
return 200;
}
return 400;
}
/**
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
private function paraFilter($para)
{
$para_filter = array();
foreach ($para as $key => $val) {
if ($key == "sign" || $key == "sign_type" || $val == "") continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
/**
* 对数组排序
* @param $para 排序前的数组
* return 排序后的数组
*/
private function argSort($para)
{
ksort($para);
reset($para);
return $para;
}
/**
* 验证回复的正确性
* @see QPay_Utils_Abstract::verifResponse()
*/
protected function checkResponse(array $arrResponse)
{
ksort($arrResponse);
reset($arrResponse);
$sign = '';
foreach ($arrResponse AS $key=>$val)
{
if ($key != 'sign' && $key != 'sign_type' && $key != 'code')
{
foreach ($arrResponse AS $key => $val) {
if ($key != 'sign' && $key != 'sign_type' && $key != 'code') {
$sign .= "$key=$val&";
}
}
$sign = substr($sign, 0, -1) . $this->config->alipay_key;
return md5($sign) != $arrResponse['sign'] ? false : true;
}
}
}
\ No newline at end of file
... ...
... ... @@ -3,108 +3,119 @@
namespace WebPlugin\Pay\Shengpay;
class Config
{
/**
* 直连方式支付地址
* Enter description here ...
* @var string
*/
var $direct_pay_url = "http://mas.sdo.com/web-acquire-channel/cashier30direct.htm";
/**
* 直连方式支付测试地址
* Enter description here ...
* @var string
*/
var $direct_pay_url_test = "http://mas.sdo.com/web-acquire-channel/cashier30direct.htm";
/**
* 非直连方式支付地址
*/
var $pay_url = "http://mas.sdo.com/web-acquire-channel/cashier30.htm";
/**
* 非直连方式支付测试地址
* Enter description here ...
* @var string
*/
var $pay_url_test = "http://mas.sdo.com/web-acquire-channel/cashier30.htm";
/**
* 版本号
* Enter description here ...
* @var string
*/
var $version = "3.0";
/**
* 商户号
* Enter description here ...
* @var unknown_type
*/
var $merchant_no = "";
/**
* 商户MD5加密串
* Enter description here ...
* @var string
*/
var $merchant_key = "";
/**
* 支付渠道,网银B2C
* Enter description here ...
* @var string
*/
var $pay_channel = "04";
/**
* 客户端回调地址
* Enter description here ...
* @var string
*/
var $post_back_url = "notice/shengpayreturn";
/**
* 服务器端通知地址
* Enter description here ...
* @var string
*/
var $notify_url = "notice/shengpaynotice";
/**
* 商户下单地址
* Enter description here ...
* @var string
*/
var $back_url = "http://www.yohobuy.com/home";
/**
* 货币类型
* Enter description here ...
* @var string
*/
var $currency_type = "RMB";
/**
* 发货通知方式
* Enter description here ...
* @var string
*/
var $notify_url_type = "http";
/**
* 签名方式,1-rsa,2-md5
* Enter description here ...
* @var string
*/
var $sign_type = "2";
/**
* 支付银行
* Enter description here ...
* @var string
*/
var $test_bank_code = "SDTBNK";
{
/**
* 直连方式支付地址
* Enter description here ...
* @var string
*/
var $direct_pay_url = "http://mas.sdo.com/web-acquire-channel/cashier30direct.htm";
/**
* 直连方式支付测试地址
* Enter description here ...
* @var string
*/
var $direct_pay_url_test = "http://mas.sdo.com/web-acquire-channel/cashier30direct.htm";
/**
* 非直连方式支付地址
*/
var $pay_url = "http://mas.sdo.com/web-acquire-channel/cashier30.htm";
/**
* 非直连方式支付测试地址
* Enter description here ...
* @var string
*/
var $pay_url_test = "http://mas.sdo.com/web-acquire-channel/cashier30.htm";
/**
* 版本号
* Enter description here ...
* @var string
*/
var $version = "3.0";
/**
* 商户号
* Enter description here ...
* @var unknown_type
*/
var $merchant_no = "";
/**
* 商户MD5加密串
* Enter description here ...
* @var string
*/
var $merchant_key = "";
/**
* 支付渠道,网银B2C
* Enter description here ...
* @var string
*/
var $pay_channel = "04";
/**
* 客户端回调地址
* Enter description here ...
* @var string
*/
var $post_back_url = "notice/shengpayreturn";
/**
* 服务器端通知地址
* Enter description here ...
* @var string
*/
var $notify_url = "notice/shengpaynotice";
/**
* 商户下单地址
* Enter description here ...
* @var string
*/
var $back_url = "http://www.yohobuy.com/home";
/**
* 货币类型
* Enter description here ...
* @var string
*/
var $currency_type = "RMB";
/**
* 发货通知方式
* Enter description here ...
* @var string
*/
var $notify_url_type = "http";
/**
* 签名方式,1-rsa,2-md5
* Enter description here ...
* @var string
*/
var $sign_type = "2";
/**
* 支付银行
* Enter description here ...
* @var string
*/
var $test_bank_code = "SDTBNK";
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/shengpay';
/**
* @var string 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
\ No newline at end of file
... ...
... ... @@ -5,151 +5,164 @@ namespace WebPlugin\Pay\Shengpay;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
class Service extends PayAbstract
{
var $config ;
public function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'shengpay';
$this->config = new Config();
$myConfig = json_decode($paymentParams["pay_params"]) ;
$this->config->merchant_no = $myConfig->merchant_id;
$this->config->merchant_key = $myConfig->merchant_key;
}
public $config;
private $log;
public function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'shengpay';
$this->config = new Config();
$myConfig = json_decode($paymentParams["pay_params"]);
$this->config->merchant_no = $myConfig->merchant_id;
$this->config->merchant_key = $myConfig->merchant_key;
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
/**
* @param Reqparams $params
* @return array|void
*/
public function getPayRequestPars(Reqparams $params)
{
$bankCode = $params->paymentParameter == 'platform' ? '' : $params->paymentParameter;
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
$parameters = array(
'Version' => $this->config->version,
'Amount' => sprintf("%.2f", $params->totalFee * 0.01),
'OrderNo' => $params->orderCode,
'MerchantNo' => $this->config->merchant_no,
'PayChannel' => $this->config->pay_channel,
'PostBackUrl' => $baseUrl . $this->config->post_back_url,
'NotifyUrl' => $baseUrl . $this->config->notify_url,
'BackUrl' => $this->config->back_url,
'OrderTime' => date('YmdHis', $params->orderTime),
'CurrencyType' => $this->config->currency_type,
'NotifyUrlType' => $this->config->notify_url_type,
'SignType' => $this->config->sign_type,
'BankCode' => $bankCode //银行代码
);
$parameters["MAC"] = $this->getSign($parameters);
$isDirect = empty($bankCode) ? false : TRUE;
$result = array(
'pay_url' => $this->getPayUrl($isDirect, $params->isTest),
'pars' => $parameters,
'reqType' => 'post'
);
return $result;
}
/**
* 获取支付地址
* Enter description here ...
* @param bool $isDirect 是否为直连
* @param bool $isTest 是否为测试环境
* @return string
*/
public function getPayUrl($isDirect, $isTest){
if($isDirect){
if($isTest){
return $this->config->direct_pay_url_test;
}else{
return $this->config->direct_pay_url;
}
} else {
if($isTest){
return $this->config->pay_url_test;
} else {
return $this->config->pay_url;
}
}
}
public function getPayRequestPars(Reqparams $params)
{
$this->log->LogInfo("===开始处理盛付通的请求参数===");
$this->log->logInfo("-----请求参数为---");
$this->log->logInfo(var_export($params));
$bankCode = $params->paymentParameter == 'platform' ? '' : $params->paymentParameter;
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
$parameters = array(
'Version' => $this->config->version,
'Amount' => sprintf("%.2f", $params->totalFee * 0.01),
'OrderNo' => $params->orderCode,
'MerchantNo' => $this->config->merchant_no,
'PayChannel' => $this->config->pay_channel,
'PostBackUrl' => $baseUrl . $this->config->post_back_url,
'NotifyUrl' => $baseUrl . $this->config->notify_url,
'BackUrl' => $this->config->back_url,
'OrderTime' => date('YmdHis', $params->orderTime),
'CurrencyType' => $this->config->currency_type,
'NotifyUrlType' => $this->config->notify_url_type,
'SignType' => $this->config->sign_type,
'BankCode' => $bankCode //银行代码
);
$parameters["MAC"] = $this->getSign($parameters);
$isDirect = empty($bankCode) ? false : TRUE;
$result = array(
'pay_url' => $this->getPayUrl($isDirect, $params->isTest),
'pars' => $parameters,
'reqType' => 'post'
);
return $result;
}
/**
* 获取支付地址
* Enter description here ...
* @param bool $isDirect 是否为直连
* @param bool $isTest 是否为测试环境
* @return string
*/
public function getPayUrl($isDirect, $isTest)
{
if ($isDirect) {
if ($isTest) {
return $this->config->direct_pay_url_test;
} else {
return $this->config->direct_pay_url;
}
} else {
if ($isTest) {
return $this->config->pay_url_test;
} else {
return $this->config->pay_url;
}
}
}
/**
* 获取签名
* @param array $pars
* @return string
*/
public function getSign(array $pars)
{
$strPars = $pars['Version'] . $pars['Amount'] . $pars['OrderNo'] . $pars['MerchantNo'] . $pars['PayChannel']
. $pars['PostBackUrl'] . $pars['NotifyUrl'] . $pars['BackUrl'] . $pars['OrderTime'] . $pars['CurrencyType']
. $pars['NotifyUrlType'] . $pars['SignType'] . $pars['BankCode'];
return md5($strPars . $this->config->merchant_key);
}
public function getSign(array $pars)
{
$strPars = $pars['Version'] . $pars['Amount'] . $pars['OrderNo'] . $pars['MerchantNo'] . $pars['PayChannel']
. $pars['PostBackUrl'] . $pars['NotifyUrl'] . $pars['BackUrl'] . $pars['OrderTime'] . $pars['CurrencyType']
. $pars['NotifyUrlType'] . $pars['SignType'] . $pars['BankCode'];
return md5($strPars . $this->config->merchant_key);
}
/**
* 解析结果
* @param array $arrResponse
* @return void|Rspparams
*/
function parseResponse(Array $arrResponse){
$rsp = new Rspparams();
if(!$this->checkResponse($arrResponse)){
//验证不成功
$rsp->payResult = -1;
}
else{
$rsp->bankName = "";
$rsp->orderCode = $arrResponse["OrderNo"];
$rsp->payResult = $this->convertResult($arrResponse["Status"]);
$rsp->payTime = time();
$rsp->totalFee = $arrResponse["Amount"];
$rsp->resultMsg = $arrResponse["ExInfo"];
//添加支付订单号和交易号
$rsp->payOrderCode = $arrResponse["orderNo"];
$rsp->tradeNo = "";
$rsp->bankBillNo = "";
}
return $rsp;
}
function parseResponse(Array $arrResponse)
{
$this->log->LogInfo("===开始处理盛付通的请求参数===");
$this->log->logInfo("-----请求参数为---");
$this->log->logInfo(var_export($arrResponse));
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
//验证不成功
$rsp->payResult = -1;
} else {
$rsp->bankName = "";
$rsp->orderCode = $arrResponse["OrderNo"];
$rsp->payResult = $this->convertResult($arrResponse["Status"]);
$rsp->payTime = time();
$rsp->totalFee = $arrResponse["Amount"];
$rsp->resultMsg = $arrResponse["ExInfo"];
//添加支付订单号和交易号
$rsp->payOrderCode = $arrResponse["orderNo"];
$rsp->tradeNo = "";
$rsp->bankBillNo = "";
}
return $rsp;
}
/**
* 验证回复的正确性
* @param array $arrResponse
* @return bool|void
*/
protected function checkResponse(array $arrResponse)
{
$strPars = $arrResponse["Amount"] . '|' . $arrResponse['PayAmount'] . '|' . $arrResponse['OrderNo'] . '|' . $arrResponse['serialno'] .
'|' . $arrResponse['Status'] . '|' . $arrResponse['MerchantNo'] . '|' . $arrResponse['PayChannel'] . '|' . $arrResponse['Discount']
. '|' . $arrResponse["SignType"] . '|' . $arrResponse['PayTime'] . '|' . $arrResponse['CurrencyType'] . '|' . $arrResponse['ProductNo']
. '|' . $arrResponse['ProductDesc'] . '|' . $arrResponse['Remark1'] . '|' . $arrResponse['Remark2'] . '|' . $arrResponse['ExInfo'];
$vaildSign = md5($strPars . '|' . $this->config->merchant_key);
if(strtoupper($vaildSign) == $arrResponse["MAC"]){
return true;
}
return false;
}
protected function checkResponse(array $arrResponse)
{
$strPars = $arrResponse["Amount"] . '|' . $arrResponse['PayAmount'] . '|' . $arrResponse['OrderNo'] . '|' . $arrResponse['serialno'] .
'|' . $arrResponse['Status'] . '|' . $arrResponse['MerchantNo'] . '|' . $arrResponse['PayChannel'] . '|' . $arrResponse['Discount']
. '|' . $arrResponse["SignType"] . '|' . $arrResponse['PayTime'] . '|' . $arrResponse['CurrencyType'] . '|' . $arrResponse['ProductNo']
. '|' . $arrResponse['ProductDesc'] . '|' . $arrResponse['Remark1'] . '|' . $arrResponse['Remark2'] . '|' . $arrResponse['ExInfo'];
$vaildSign = md5($strPars . '|' . $this->config->merchant_key);
if (strtoupper($vaildSign) == $arrResponse["MAC"]) {
return true;
}
return false;
}
/**
* @param $resultCode
* @return int|void
*/
protected function convertResult($resultCode)
{
if($resultCode == "01") //20为支付成功,30为支付失败
{
return 200;
}
return $resultCode;
}
protected function convertResult($resultCode)
{
if ($resultCode == "01") //20为支付成功,30为支付失败
{
return 200;
}
return $resultCode;
}
}
\ No newline at end of file
... ...
... ... @@ -4,53 +4,64 @@ namespace WebPlugin\Pay\Tenpay;
class Config
{
/**
* 支付请求的地址
* Enter description here ...
* @var string
*/
var $pay_url = "https://www.tenpay.com/cgi-bin/v1.0/pay_gate.cgi";
/**
* 业务代码,财付通支付接口用户填1
* Enter description here ...
* @var Integer
*/
var $cmdno = 1;
/**
* 银行类型,财务通添0
* Enter description here ...
* @var Integer
*/
var $bank_type = 0;
/**
* 商户ID
* Enter description here ...
* @var String
*/
var $bargainor_id = "";
/**
* 商户Key
* Enter description here ...
* @var unknown_type
*/
var $sp_key = "";
/**
* 接受财付通返回结果的url
* Enter description here ...
* @var unknown_type
*/
var $return_url = "notice/tenpay";
/**
* 货币类型
* Enter description here ...
* @var unknown_type
*/
var $fee_type = 1; //人民币
/**
* 支付请求的地址
* Enter description here ...
* @var string
*/
var $pay_url = "https://www.tenpay.com/cgi-bin/v1.0/pay_gate.cgi";
/**
* 业务代码,财付通支付接口用户填1
* Enter description here ...
* @var Integer
*/
var $cmdno = 1;
/**
* 银行类型,财务通添0
* Enter description here ...
* @var Integer
*/
var $bank_type = 0;
/**
* 商户ID
* Enter description here ...
* @var String
*/
var $bargainor_id = "";
/**
* 商户Key
* Enter description here ...
* @var unknown_type
*/
var $sp_key = "";
/**
* 接受财付通返回结果的url
* Enter description here ...
* @var unknown_type
*/
var $return_url = "notice/tenpay";
/**
* 货币类型
* Enter description here ...
* @var unknown_type
*/
var $fee_type = 1; //人民币
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/tenpay';
/**
* @var string 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
\ No newline at end of file
... ...
... ... @@ -5,11 +5,13 @@ namespace WebPlugin\Pay\Tenpay;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
class Service extends PayAbstract
{
var $config;
public $config;
private $log;
/**
* Service constructor.
... ... @@ -22,6 +24,8 @@ class Service extends PayAbstract
$myConfig = json_decode($paymentParams["pay_params"]);
$this->config->bargainor_id = $myConfig->merchant_id;
$this->config->sp_key = $myConfig->merchant_key;
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
/**
... ... @@ -30,6 +34,10 @@ class Service extends PayAbstract
*/
public function getPayRequestPars(Reqparams $params)
{
$this->log->LogInfo("===开始处理财付通的请求参数===");
$this->log->logInfo("-----请求参数为---");
$this->log->logInfo(var_export($params));
parent::getPayRequestPars($params);
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
... ... @@ -68,6 +76,10 @@ class Service extends PayAbstract
*/
public function parseResponse(array $arrResponse)
{
$this->log->LogInfo("===开始处理财付通的回调参数===");
$this->log->logInfo("-----回调参数为---");
$this->log->logInfo(var_export($arrResponse));
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
//验证不成功
... ...
... ... @@ -3,8 +3,7 @@
function EncryptedPin($sPin, $sCardNo ,$sPubKeyURL)
{
global $log;
$sPubKeyURL = trim(SDK_ENCRYPT_CERT_PATH," ");
// $log->LogInfo("DisSpaces : " . PubKeyURL);
$sPubKeyURL = trim(dirname(__FILE__) . '/../' . SDK_ENCRYPT_CERT_PATH," ");
$fp = fopen($sPubKeyURL, "r");
if ($fp != NULL)
{
... ...
<?php
// 初始化日志
use WebPlugin\Pay\Unionpayweb\Func\PhpLog;
use WebPlugin\PhpLog;
$log = new PhpLog (SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL);
/**
... ...
<?php
use WebPlugin\Pay\Unionpayweb\Func\PhpLog;
use WebPlugin\PhpLog;
include_once 'PublicEncrypte.php';
... ... @@ -23,7 +23,8 @@ function sign(&$params)
$params_sha1x16 = sha1($params_str, FALSE);
$log->LogInfo("摘要sha1x16 >" . $params_sha1x16);
// 签名证书路径
$cert_path = SDK_SIGN_CERT_PATH;
$cert_path = dirname(__FILE__) . '/../' . SDK_SIGN_CERT_PATH;
$log->logInfo($cert_path);
$private_key = getPrivateKey($cert_path);
// 签名
$sign_falg = openssl_sign($params_sha1x16, $signature, $private_key, OPENSSL_ALGO_SHA1);
... ... @@ -45,7 +46,7 @@ function sign(&$params)
*/
function verify($params)
{
$log = new PhpLog (SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL);;
$log = new PhpLog (SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL);
// 公钥
$public_key = getPulbicKeyByCertId($params ['certId']);
// echo $public_key.'<br/>';
... ... @@ -71,10 +72,10 @@ function verify($params)
*/
function getPulbicKeyByCertId($certId)
{
$log = new PhpLog (SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL);;
$log = new PhpLog (SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL);
$log->LogInfo('报文返回的证书ID>' . $certId);
// 证书目录
$cert_dir = SDK_VERIFY_CERT_DIR;
$cert_dir = dirname(__FILE__) . '/../' . SDK_VERIFY_CERT_DIR;
$log->LogInfo('验证签名证书目录 :>' . $cert_dir);
$handle = opendir($cert_dir);
if ($handle) {
... ... @@ -139,13 +140,13 @@ function getSignCertId()
{
// 签名证书路径
return getCertId(SDK_SIGN_CERT_PATH);
return getCertId(dirname(__FILE__) . '/../' . SDK_SIGN_CERT_PATH);
}
function getEncryptCertId()
{
// 签名证书路径
return getCertIdByCerPath(SDK_ENCRYPT_CERT_PATH);
return getCertIdByCerPath(dirname(__FILE__) . '/../' . SDK_ENCRYPT_CERT_PATH);
}
/**
... ... @@ -195,7 +196,7 @@ function encryptPan($pan)
*/
function encryptPin($pan, $pwd)
{
$cert_path = SDK_ENCRYPT_CERT_PATH;
$cert_path = dirname(__FILE__) . '/../' . SDK_ENCRYPT_CERT_PATH;
$public_key = getPublicKey($cert_path);
return EncryptedPin($pwd, $pan, $public_key);
... ... @@ -209,7 +210,7 @@ function encryptPin($pan, $pwd)
*/
function encryptCvn2($cvn2)
{
$cert_path = SDK_ENCRYPT_CERT_PATH;
$cert_path = dirname(__FILE__) . '/../' . SDK_ENCRYPT_CERT_PATH;
$public_key = getPublicKey($cert_path);
openssl_public_encrypt($cvn2, $crypted, $public_key);
... ... @@ -225,7 +226,7 @@ function encryptCvn2($cvn2)
*/
function encryptDate($certDate)
{
$cert_path = SDK_ENCRYPT_CERT_PATH;
$cert_path = dirname(__FILE__) . '/../' . SDK_ENCRYPT_CERT_PATH;
$public_key = getPublicKey($cert_path);
openssl_public_encrypt($certDate, $crypted, $public_key);
... ... @@ -241,7 +242,7 @@ function encryptDate($certDate)
*/
function encryptDateType($certDataType)
{
$cert_path = SDK_ENCRYPT_CERT_PATH;
$cert_path = dirname(__FILE__) . '/../' . SDK_ENCRYPT_CERT_PATH;
$public_key = getPublicKey($cert_path);
openssl_public_encrypt($certDataType, $crypted, $public_key);
... ...
... ... @@ -5,7 +5,7 @@ namespace WebPlugin\Pay\Unionpayweb;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\Pay\Unionpayweb\Func\PhpLog;
use WebPlugin\PhpLog;
class Service extends PayAbstract
{
... ... @@ -14,7 +14,7 @@ class Service extends PayAbstract
public function __construct(array $paymentParams)
{
$env = APPLICATION_ENV == 'production' ? 'release' : 'test';
$env = (APPLICATION_ENV === 'production' || APPLICATION_ENV === 'preview') ? 'release' : 'test';
include_once 'conf/' . $env . '/SDKConfig.php';
include_once 'Func/common.php';
include_once 'Func/secureUtil.php';
... ...
... ... @@ -11,19 +11,19 @@ const SDK_PAN_ENC = 0;
// 签名证书路径 (联系运营获取两码,在CFCA网站下载后配置,自行设置证书密码并配置)
const SDK_SIGN_CERT_PATH = '/Data/code/git/web/yohobuy/library/WebPlugin/Pay/Unionpayweb/conf/release/certs/pc_online_banking.pfx';
const SDK_SIGN_CERT_PATH = 'conf/release/certs/pc_online_banking.pfx';
// 签名证书密码
const SDK_SIGN_CERT_PWD = 'yoho12';
// 验签证书
const SDK_VERIFY_CERT_PATH = '/Data/code/git/web/yohobuy/library/WebPlugin/Pay/Unionpayweb/conf/release/certs/UpopRsaCert.cer';
const SDK_VERIFY_CERT_PATH = 'conf/release/certs/UpopRsaCert.cer';
// 密码加密证书
const SDK_ENCRYPT_CERT_PATH = '/Data/code/git/web/yohobuy/library/WebPlugin/Pay/Unionpayweb/conf/release/certs/RSA2048_PROD_index_22.cer';
const SDK_ENCRYPT_CERT_PATH = 'conf/release/certs/RSA2048_PROD_index_22.cer';
// 验签证书路径
const SDK_VERIFY_CERT_DIR = '/Data/code/git/web/yohobuy/library/WebPlugin/Pay/Unionpayweb/conf/release/certs/';
const SDK_VERIFY_CERT_DIR = 'conf/release/certs/';
// 前台请求地址
const SDK_FRONT_TRANS_URL = 'https://gateway.95516.com/gateway/api/frontTransReq.do';
... ... @@ -56,10 +56,10 @@ const SDK_BACK_NOTIFY_URL = 'http://pay.yohobuy.com/notify/unionpaywebnotice';
const SDK_FILE_DOWN_PATH = '/tmp/unionpay/files/';
//日志 目录
const SDK_LOG_FILE_PATH = '/tmp/unionpay/logs/';
const SDK_LOG_FILE_PATH = '/tmp/logs/unionpay/';
//日志级别
const SDK_LOG_LEVEL = 6;
const SDK_LOG_LEVEL = 2; // 记录信息日志
... ...
... ... @@ -9,17 +9,17 @@ const SDK_PAN_ENC = 0;
// ######(以下配置为PM环境:入网测试环境用,生产环境配置见文档说明)#######
// 签名证书路径
//const SDK_SIGN_CERT_PATH = 'D:\\wamp\\www\\yohobuy\\library\\WebPlugin\\Pay\\Unionpayweb\\conf\\test\\certs\\PM_700000000000001_acp.pfx';
const SDK_SIGN_CERT_PATH = '/Data/code/git/web/yohobuy/library/WebPlugin/Pay/Unionpayweb/conf/test/certs/PM_700000000000001_acp.pfx';
const SDK_SIGN_CERT_PATH = 'conf/test/certs/PM_700000000000001_acp.pfx';
// 签名证书密码
const SDK_SIGN_CERT_PWD = '000000';
// 密码加密证书(这条用不到的请随便配)
const SDK_ENCRYPT_CERT_PATH = '/Data/code/git/web/yohobuy/library/WebPlugin/Pay/Unionpayweb/conf/test/certs/verify_sign_acp.cer';
const SDK_ENCRYPT_CERT_PATH = 'conf/test/certs/verify_sign_acp.cer';
//const SDK_ENCRYPT_CERT_PATH = 'D:\\wamp\\www\\yohobuy\\library\\WebPlugin\\Pay\\Unionpayweb\\conf\\test\\certs\\verify_sign_acp.cer';
// 验签证书路径(请配到文件夹,不要配到具体文件)
const SDK_VERIFY_CERT_DIR = '/Data/code/git/web/yohobuy/library/WebPlugin/Pay/Unionpayweb/conf/test/certs/';
const SDK_VERIFY_CERT_DIR = 'conf/test/certs/';
// 前台请求地址
const SDK_FRONT_TRANS_URL = 'https://101.231.204.80:5000/gateway/api/frontTransReq.do';
... ... @@ -52,7 +52,7 @@ const SDK_BACK_NOTIFY_URL = 'http://pay.test.yohobuy.com/notify/unionpaywebnotic
const SDK_FILE_DOWN_PATH = '/tmp/unionpay/files/';
//日志 目录
const SDK_LOG_FILE_PATH = '/tmp/unionpay/logs/';
const SDK_LOG_FILE_PATH = '/tmp/logs/unionpay/';
//日志级别
const SDK_LOG_LEVEL = 2;
... ...
... ... @@ -15,4 +15,14 @@ class Config
//平台app_key private_key
var $app_key = "adbf5a778175ee75";
var $private_key = "adbf5a778175ee757c34d0eba4e932bc";
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/wechatqrcode';
/**
* @var string 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
\ No newline at end of file
... ...
... ... @@ -8,6 +8,7 @@ use WebPlugin\Pay\Rspparams;
use WebPlugin\Pay\Signature;
use WebPlugin\Pay\weixin\lib\WxPayApi;
use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
use WebPlugin\PhpLog;
class Service extends PayAbstract
{
... ... @@ -18,6 +19,7 @@ class Service extends PayAbstract
private $appKey;
private $privateKey;
private $payCurl;
private $log;
public function __construct(array $paymentParams) {
$this->logProjectPrefix = 'wechatpay';
... ... @@ -27,6 +29,8 @@ class Service extends PayAbstract
$this->appKey = $this->config->app_key;
$this->privateKey = $this->config->private_key;
$this->paymentCode = $paymentParams['id'];
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
public function getPayRequestPars(Reqparams $params) {
... ... @@ -46,6 +50,10 @@ class Service extends PayAbstract
* @internal param array $orderCode
*/
public function pay(array $orderInfo) {
$this->log->LogInfo("===开始处理微信扫码支付的请求参数===");
$this->log->logInfo("-----请求参数为---");
$this->log->logInfo(var_export($orderInfo));
//生成签名
$this->orderCode = $orderInfo['order_code'];
$payParams = array(
... ... @@ -72,7 +80,13 @@ class Service extends PayAbstract
'pay_url' => $this->payCurl,
'pars' => trim($pars, '&')
);
$this->log->LogInfo("===开始处理微信扫码支付的支付地址===");
$this->log->logInfo("-----支付地址数据为---");
$this->log->logInfo(var_export($payUrlInfo));
$payUrl = $payUrlInfo['pay_url'] . '?' . $payUrlInfo['pars'];
return array('pay_url' => $payUrl);
}
... ... @@ -80,12 +94,18 @@ class Service extends PayAbstract
/* 返回示例
* http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435
*/
$this->log->LogInfo("===开始查询微信扫码支付的结果===");
// 组装微信支付的订单号
$tradeNo = 'YOHOBuy_' . $data['orderCode'];
$input = new WxPayOrderQuery();
$input->SetOut_trade_no($tradeNo);
$result = WxPayApi::orderQuery($input);
$this->log->logInfo("===查询微信扫码支付的结果结束,结果为===");
$this->log->logInfo(var_export($result));
$rsp = new Rspparams();
// 支付成功
if(isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS'){
... ...
<?php
namespace WebPlugin\Pay\Unionpayweb\Func;
class PhpLog
{
const DEBUG = 1;// Most Verbose
const INFO = 2;// ...
const WARN = 3;// ...
const ERROR = 4;// ...
const FATAL = 5;// Least Verbose
const OFF = 6;// Nothing at all.
const LOG_OPEN = 1;
const OPEN_FAILED = 2;
const LOG_CLOSED = 3;
/* Public members: Not so much of an example of encapsulation, but that's okay. */
public $Log_Status = PhpLog::LOG_CLOSED;
public $DateFormat = "Y-m-d G:i:s";
public $MessageQueue;
private $filename;
private $log_file;
private $priority = PhpLog::INFO;
private $file_handle;
/**
* AUTHOR: gu_yongkang
* DATA: 20110322
* Enter description here ...
* @param $filepath
* 文件存储的路径
* @param $timezone
* 时间格式,此处设置为"PRC"(中国)
* @param $priority
*
* 设置运行级别
*/
public function __construct($filepath, $timezone, $priority)
{
if ($priority == PhpLog::OFF) return;
$this->filename = date('Y-m-d', time()) . '.log'; //默认为以时间+.log的文件文件
$this->log_file = $this->createPath($filepath, $this->filename);
$this->MessageQueue = array();
$this->priority = $priority;
date_default_timezone_set($timezone);
if (!file_exists($filepath)) //判断文件路径是否存在
{
if (!empty($filepath)) //判断路径是否为空
{
if (!($this->_createDir($filepath))) {
die("创建目录失败!");
}
if (!is_writable($this->log_file)) {
$this->Log_Status = PhpLog::OPEN_FAILED;
$this->MessageQueue[] = "The file exists, but could not be opened for writing. Check that appropriate permissions have been set.";
return;
}
}
}
if ($this->file_handle = fopen($this->log_file, "a+")) {
$this->Log_Status = PhpLog::LOG_OPEN;
$this->MessageQueue[] = "The log file was opened successfully.";
} else {
$this->Log_Status = PhpLog::OPEN_FAILED;
$this->MessageQueue[] = "The file could not be opened. Check permissions.";
}
return;
}
public function __destruct()
{
if ($this->file_handle)
fclose($this->file_handle);
}
/**
*作用:创建目录
*输入:要创建的目录
*输出:true | false
*/
private function _createDir($dir)
{
return is_dir($dir) or (self::_createDir(dirname($dir)) and mkdir($dir, 0777));
}
/**
*作用:构建路径
*输入:文件的路径,要写入的文件名
*输出:构建好的路径字串
*/
private function createPath($dir, $filename)
{
if (empty($dir)) {
return $filename;
} else {
return $dir . "/" . $filename;
}
}
public function LogInfo($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::INFO, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
public function LogDebug($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::DEBUG, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
public function LogWarn($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::WARN, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
public function LogError($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::ERROR, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
public function LogFatal($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::FATAL, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
/**
* Author : gu_yongkang
* Enter description here ...
* @param unknown_type $line
* content 内容
* @param unknown_type $priority
* 打印级别
* @param unknown_type $sFile
* 调用打印日志的文件名
* @param unknown_type $iLine
* 打印文件的位置(行数)
*/
public function Log($line, $priority, $sFile, $iLine)
{
if ($iLine > 0) {
// $line = iconv('GBK', 'UTF-8', $line);
if ($this->priority <= $priority) {
$status = $this->getTimeLine($priority, $sFile, $iLine);
$this->WriteFreeFormLine("$status $line \n");
}
} else {
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
if ($this->priority <= $priority) {
$status = $this->getTimeLine($priority, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
$this->WriteFreeFormLine("$status $line \n");
}
}
}
// 支持输入多个参数
public function WriteFreeFormLine($line)
{
if ($this->Log_Status == PhpLog::LOG_OPEN && $this->priority != PhpLog::OFF) {
if (fwrite($this->file_handle, $line) === false) {
$this->MessageQueue[] = "The file could not be written to. Check that appropriate permissions have been set.";
}
}
}
private function getRemoteIP()
{
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
$ip = trim($ip);
if (!empty($ip)) {
return $ip;
}
}
}
}
return "_NO_IP";
}
private function getTimeLine($level, $FilePath, $FileLine)
{
$time = date($this->DateFormat);
$ip = $this->getRemoteIP();
switch ($level) {
case PhpLog::INFO:
return "$time, " . "INFO, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
case PhpLog::WARN:
return "$time, " . "WARN, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
case PhpLog::DEBUG:
return "$time, " . "DEBUG, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
case PhpLog::ERROR:
return "$time, " . "ERROR, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
case PhpLog::FATAL:
return "$time, " . "FATAL, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
default:
return "$time, " . "LOG, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
}
}
}
?>
<?php
namespace WebPlugin;
/**
* 日志记录类
*
* @package WebPlugin
* @author Gtskk
* @copyright 2016/4/25 13:48 Gtskk<iamgtskk@gmail.com>
* @version: 0.0.1
*/
class PhpLog
{
const DEBUG = 1;// Most Verbose
const INFO = 2;// ...
const WARN = 3;// ...
const ERROR = 4;// ...
const FATAL = 5;// Least Verbose
const OFF = 6;// Nothing at all.
const LOG_OPEN = 1;
const OPEN_FAILED = 2;
const LOG_CLOSED = 3;
public $Log_Status = PhpLog::LOG_CLOSED;
public $DateFormat = "Y-m-d G:i:s";
public $MessageQueue;
private $filename;
private $log_file;
private $priority = PhpLog::INFO;
private $file_handle;
/**
* 日志记录类构造函数
*
* @param string $filepath 文件存储的路径
* @param string $timezone 时间格式,此处设置为"PRC"(中国)
* @param $priority
* 设置运行级别
*/
public function __construct($filepath, $timezone, $priority)
{
if ($priority == PhpLog::OFF) return;
$this->filename = date('Y-m-d', time()) . '.log'; //默认为以时间+.log的文件文件
$this->log_file = $this->createPath($filepath, $this->filename);
$this->MessageQueue = array();
$this->priority = $priority;
date_default_timezone_set($timezone);
if (!file_exists($filepath)) //判断文件路径是否存在
{
if (!empty($filepath)) //判断路径是否为空
{
if (!($this->_createDir($filepath))) {
die("创建目录失败!");
}
if (!is_writable($this->log_file)) {
$this->Log_Status = PhpLog::OPEN_FAILED;
$this->MessageQueue[] = "The file exists, but could not be opened for writing. Check that appropriate permissions have been set.";
return;
}
}
}
if ($this->file_handle = fopen($this->log_file, "a+")) {
$this->Log_Status = PhpLog::LOG_OPEN;
$this->MessageQueue[] = "The log file was opened successfully.";
} else {
$this->Log_Status = PhpLog::OPEN_FAILED;
$this->MessageQueue[] = "The file could not be opened. Check permissions.";
}
return;
}
public function __destruct()
{
if ($this->file_handle)
fclose($this->file_handle);
}
/**
*作用:创建目录
*输入:要创建的目录
*输出:true | false
*/
private function _createDir($dir)
{
return is_dir($dir) or (self::_createDir(dirname($dir)) and mkdir($dir, 0777));
}
/**
*作用:构建路径
*输入:文件的路径,要写入的文件名
*输出:构建好的路径字串
*/
private function createPath($dir, $filename)
{
if (empty($dir)) {
return $filename;
} else {
return $dir . "/" . $filename;
}
}
public function LogInfo($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::INFO, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
public function LogDebug($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::DEBUG, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
public function LogWarn($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::WARN, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
public function LogError($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::ERROR, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
public function LogFatal($line)
{
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
$this->Log($line, PhpLog::FATAL, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
}
/**
* Author : gu_yongkang
* Enter description here ...
* @param unknown_type $line
* content 内容
* @param unknown_type $priority
* 打印级别
* @param unknown_type $sFile
* 调用打印日志的文件名
* @param unknown_type $iLine
* 打印文件的位置(行数)
*/
public function Log($line, $priority, $sFile, $iLine)
{
if ($iLine > 0) {
// $line = iconv('GBK', 'UTF-8', $line);
if ($this->priority <= $priority) {
$status = $this->getTimeLine($priority, $sFile, $iLine);
$this->WriteFreeFormLine("$status $line \n");
}
} else {
/**
* AUTHOR : gu_yongkang
* 增加打印函数和文件名的功能
*/
$sAarray = array();
$sAarray = debug_backtrace();
$sGetFilePath = $sAarray[0]["file"];
$sGetFileLine = $sAarray[0]["line"];
if ($this->priority <= $priority) {
$status = $this->getTimeLine($priority, $sGetFilePath, $sGetFileLine);
unset($sAarray);
unset($sGetFilePath);
unset($sGetFileLine);
$this->WriteFreeFormLine("$status $line \n");
}
}
}
// 支持输入多个参数
public function WriteFreeFormLine($line)
{
if ($this->Log_Status == PhpLog::LOG_OPEN && $this->priority != PhpLog::OFF) {
if (fwrite($this->file_handle, $line) === false) {
$this->MessageQueue[] = "The file could not be written to. Check that appropriate permissions have been set.";
}
}
}
private function getRemoteIP()
{
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
$ip = trim($ip);
if (!empty($ip)) {
return $ip;
}
}
}
}
return "_NO_IP";
}
private function getTimeLine($level, $FilePath, $FileLine)
{
$time = date($this->DateFormat);
$ip = $this->getRemoteIP();
switch ($level) {
case PhpLog::INFO:
return "$time, " . "INFO, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
case PhpLog::WARN:
return "$time, " . "WARN, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
case PhpLog::DEBUG:
return "$time, " . "DEBUG, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
case PhpLog::ERROR:
return "$time, " . "ERROR, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
case PhpLog::FATAL:
return "$time, " . "FATAL, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
default:
return "$time, " . "LOG, " . "$ip, " . "File[ $FilePath ], " . "Line[$FileLine]" . "------";
}
}
}
\ No newline at end of file
... ...
... ... @@ -124,7 +124,7 @@ class NoticeController extends WebAction
}
/*
* 支付宝支付回调
* 支付宝银行支付回调(用于后台同步)
*/
public function alibanknoticeAction()
{
... ... @@ -140,6 +140,9 @@ class NoticeController extends WebAction
exit();
}
/*
* 支付宝银行支付回调(用于前台同步)
*/
public function alibankreturnAction()
{
$payment = PayModel::getPaymentById(12);
... ...