当支付宝和微信支付成功后,我们在回调方法里记录订单状态方便我们去调试和查验支付结果。
第一种将接收的生成日志txt文件,记录信息在本地
function log_result($file, $word) {
$fp4 = fopen($file, "r"); //只读打开模板,底部;
$str = fread($fp4, filesize($file)); //读取模板内容
$str = $str . "\n执行日期:" . date("Y-m-d H:i:s") . "\n" . $word . "\n\n";
$handle = fopen($file, "w"); //不存在就创建;,创建页面
fwrite($handle, $str);
}
使用方法:
$this->log_result($log_name, "【接收到的notify接受信息】:商户订单号:".$trade_no.'|'.$verify_result['out_transaction_id'].";订单号:".$verify_result['out_trade_no'].'状态'.$flag.'钱:'.$money.'id:'.$order_id."\n签名结束\n");
第二种将数据记录在数据库中:
1.创建支付宝支付记录数据表:
CREATE TABLE `site_pay_ali` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pay_scene` tinyint(1) NOT NULL DEFAULT '1' COMMENT '支付场景',
`oid` int(11) NOT NULL COMMENT '订单id',
`order_number` int(11) NOT NULL COMMENT '订单号',
`subject` varchar(100) NOT NULL COMMENT '支付主题',
`buyer_id` varchar(20) NOT NULL COMMENT '买家支付宝用户号',
`total_amount` varchar(20) NOT NULL COMMENT '总金额',
`sign_type` varchar(10) NOT NULL COMMENT '签名类型',
`trade_no` varchar(80) NOT NULL COMMENT '支付宝交易号',
`app_id` varchar(50) NOT NULL COMMENT '开发者的app_id',
`buyer_logon_id` varchar(100) NOT NULL COMMENT '买家支付宝帐号',
`notify_time` varchar(100) NOT NULL COMMENT '支付时间',
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.创建微信支付记录表
CREATE TABLE `site_pay_wx` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pay_scene` tinyint(1) NOT NULL DEFAULT '1' COMMENT '支付场景',
`oid` int(11) NOT NULL COMMENT '订单id',
`order_number` int(11) NOT NULL COMMENT '订单号',
`attach` varchar(300) NOT NULL COMMENT '支付主题',
`bank_type` varchar(20) NOT NULL COMMENT '付款银行',
`cash_fee` int(11) NOT NULL COMMENT '现金支付金额',
`fee_type` varchar(20) NOT NULL COMMENT '货币种类',
`nonce_str` varchar(50) NOT NULL COMMENT '随机字符串',
`openid` varchar(300) NOT NULL COMMENT '用户标识',
`sign` varchar(50) NOT NULL COMMENT '签名',
`is_subscribe` tinyint(1) NOT NULL COMMENT '是否关注公众账号',
`time_end` varchar(20) NOT NULL COMMENT '支付时间',
`transaction_id` varchar(50) NOT NULL COMMENT '微信支付订单号',
`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 '用户国家',
`headimgurl` varchar(500) DEFAULT NULL COMMENT '用户头像',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='微信支付信息表';
添加微信支付数据:
/**
* 增加微信支付完成记录
* @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;
如没特殊注明,文章均为方维网络原创,转载请注明来自https://www.szfangwei.cn/news/6493.html