當(dāng)支付寶和微信支付成功后,我們?cè)诨卣{(diào)方法里記錄訂單狀態(tài)方便我們?nèi)フ{(diào)試和查驗(yàn)支付結(jié)果。
第一種將接收的生成日志txt文件,記錄信息在本地
function log_result($file, $word) {
$fp4 = fopen($file, "r"); //只讀打開模板,底部;
$str = fread($fp4, filesize($file)); //讀取模板內(nèi)容
$str = $str . "\n執(zhí)行日期:" . date("Y-m-d H:i:s") . "\n" . $word . "\n\n";
$handle = fopen($file, "w"); //不存在就創(chuàng)建;,創(chuàng)建頁(yè)面
fwrite($handle, $str);
}
使用方法:
$this->log_result($log_name, "【接收到的notify接受信息】:商戶訂單號(hào):".$trade_no.'|'.$verify_result['out_transaction_id'].";訂單號(hào):".$verify_result['out_trade_no'].'狀態(tài)'.$flag.'錢:'.$money.'id:'.$order_id."\n簽名結(jié)束\n");
第二種將數(shù)據(jù)記錄在數(shù)據(jù)庫(kù)中:
1.創(chuàng)建支付寶支付記錄數(shù)據(jù)表:
CREATE TABLE `site_pay_ali` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pay_scene` tinyint(1) NOT NULL DEFAULT '1' COMMENT '支付場(chǎng)景',
`oid` int(11) NOT NULL COMMENT '訂單id',
`order_number` int(11) NOT NULL COMMENT '訂單號(hào)',
`subject` varchar(100) NOT NULL COMMENT '支付主題',
`buyer_id` varchar(20) NOT NULL COMMENT '買家支付寶用戶號(hào)',
`total_amount` varchar(20) NOT NULL COMMENT '總金額',
`sign_type` varchar(10) NOT NULL COMMENT '簽名類型',
`trade_no` varchar(80) NOT NULL COMMENT '支付寶交易號(hào)',
`app_id` varchar(50) NOT NULL COMMENT '開發(fā)者的app_id',
`buyer_logon_id` varchar(100) NOT NULL COMMENT '買家支付寶帳號(hào)',
`notify_time` varchar(100) NOT NULL COMMENT '支付時(shí)間',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='支付寶支付記錄';
/**
* 增加支付寶支付完成記錄
* @param $data
* @param string $model
* @return mixed
*/
public function addRecord($data, $model = '') {
$model = $model == '' ? D('Order') : $model;
$oid = $model->where(array('order_number' => $data['out_trade_no']))->field('id')->find();
$savedata = array(
'pay_scene' => $data['pay_scene'] ? $data['pay_scene'] : 1,
'oid' => $oid['id'],
'order_number' => $data['out_trade_no'],
'subject' => $data['subject'],
'buyer_id' => $data['buyer_id'],
'total_amount' => $data['total_amount'],
'sign_type' => $data['sign_type'],
'trade_no' => $data['trade_no'],
'app_id' => $data['app_id'],
'buyer_logon_id' => $data['buyer_logon_id'],
'notify_time' => $data['notify_time'],
);
$re = $this->data($savedata)->add();
return $re;
}
2.創(chuàng)建微信支付記錄表
CREATE TABLE `site_pay_wx` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pay_scene` tinyint(1) NOT NULL DEFAULT '1' COMMENT '支付場(chǎng)景',
`oid` int(11) NOT NULL COMMENT '訂單id',
`order_number` int(11) NOT NULL COMMENT '訂單號(hào)',
`attach` varchar(300) NOT NULL COMMENT '支付主題',
`bank_type` varchar(20) NOT NULL COMMENT '付款銀行',
`cash_fee` int(11) NOT NULL COMMENT '現(xiàn)金支付金額',
`fee_type` varchar(20) NOT NULL COMMENT '貨幣種類',
`nonce_str` varchar(50) NOT NULL COMMENT '隨機(jī)字符串',
`openid` varchar(300) NOT NULL COMMENT '用戶標(biāo)識(shí)',
`sign` varchar(50) NOT NULL COMMENT '簽名',
`is_subscribe` tinyint(1) NOT NULL COMMENT '是否關(guān)注公眾賬號(hào)',
`time_end` varchar(20) NOT NULL COMMENT '支付時(shí)間',
`transaction_id` varchar(50) NOT NULL COMMENT '微信支付訂單號(hào)',
`nickname` varchar(300) CHARACTER SET utf8mb4 NOT NULL COMMENT '用戶昵稱',
`sex` tinyint(1) NOT NULL DEFAULT '1' COMMENT '用戶性別',
`city` varchar(50) DEFAULT NULL COMMENT '用戶城市',
`province` varchar(50) DEFAULT NULL COMMENT '用戶省份',
`country` varchar(50) DEFAULT NULL COMMENT '用戶國(guó)家',
`headimgurl` varchar(500) DEFAULT NULL COMMENT '用戶頭像',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='微信支付信息表';
添加微信支付數(shù)據(jù):
/**
* 增加微信支付完成記錄
* @param $data
* @param string $model
* @return int|mixed
*/
public function addRecord($data, $model = '') {
$model = $model == '' ? D('Order') : $model;
$oid = $model->where(array('order_number' => $data['out_trade_no']))->field('id')->find();
$userInfo = S('userInfo');
$savedata = array(
'pay_scene' => $data['pay_scene'] ? $data['pay_scene'] : 1,
'oid' => $oid['id'],
'order_number' => $data['out_trade_no'],
'attach' => $data['attach'],
'bank_type' => $data['bank_type'],
'cash_fee' => $data['cash_fee'],
'fee_type' => $data['fee_type'],
'nonce_str' => $data['nonce_str'],
'openid' => $data['openid'],
'sign' => $data['sign'],
'is_subscribe' => $data['is_subscribe'],
'time_end' => $data['time_end'],
'transaction_id' => $data['transaction_id'],
'nickname' => base64_encode($userInfo['nickname']),
'sex' => $userInfo['sex'],
'city' => $userInfo['city'],
'province' => $userInfo['province'],
'country' => $userInfo['country'],
'headimgurl' => $userInfo['headimgurl'],
);
$re = $this->where(array('order_number' => $data['out_trade_no']))->find();
if (!$re) {
$re = $this->data($savedata)->add();
return $re;
} else {
return -1;
如沒(méi)特殊注明,文章均為方維網(wǎng)絡(luò)原創(chuàng),轉(zhuǎn)載請(qǐng)注明來(lái)自http://m.oulysa.com/news/6493.html