php版新浪支付接口之回调接口笔记
发布:smiling 来源: PHP粉丝网 添加日期:2018-09-14 11:17:58 浏览: 评论:0
所谓的新浪回调接口,就是当资金充值成功之后,新浪会通知本网站一个信息来告知已经充值成功,并返回一组成功的数组,我们根据这些数据再进行一个本地数据库的同步操作,比如更新本地数据库是否充值成功的状态,由未支付改为已支付,然后再网站上面进行显示,还有资金也会进行同步 update,好了,下面夏日博客把日志分享下来,接着上一篇新浪支付新建接口,一个简单的新浪支付回调接口,这个异步回调的信息是通过日志生成到ftp下面的,根据日志进行本地的更新。
一,先查看日志文件
说明:数据提交到新浪之后会生成新浪日志文件,如下:
- {"ctl":"collocation","act":"response_sina","call":"registercreditor","notify_time":"20160317112508","sign_type":"RSA","notify_type":"trade_status_sync","gmt_payment":"20160317111255","trade_status":"PAY_FINISHED","version":"1.0","sign":"ULbWNFkn1DhF1z9M5daaJHKcvlyTCHS1SmH3o7AMwAQnYylMQATfpNXzdloFh5R43cm3MTaTuaAxEddSRckMBzemZ+XlqEcERsu8x6HA0OnIZW5YVOgQhPfnz4lbH3MC4yjxPzq9dQgE\/fVLJ+pWnaeVtXJMiyRygohCdX+mT28=","gmt_create":"20160317111254","_input_charset":"utf-8","outer_trade_no":"7L3No20160317111143","trade_amount":"100.00","inner_trade_no":"101145818437424877398","notify_id":"82170f9981b84c40b50a634ed37a2afd"}
二,打开 /app/lib/module/collocationModule.class.php,查找 response_sina 方法,方法如下:
- public function response_sina() {
- $content= $_REQUEST;
- error_log( date ( "[YmdHis]" ) ."\t" . json_encode($content) . "\r\n", 3, '../'. date ( "Y-m-d" ) . '.log1' );
- $class_name = getCollName();
- require_once APP_ROOT_PATH."system/collocation/".$class_name."_collocation.php";
- $collocation_class = $class_name."_collocation";
- $collocation_object = new $collocation_class();
- $collocation_code = $collocation_object->SinaNotify($_POST,$_REQUEST);
- }
三,打开 system/collocation/Sina_collocation.php 文件,查找 SinaNotify 方法,如下:
- function SinaNotify($map,$data){
- // $weibopay->write_log("获取到refund_status_sync结果通知:单号:".json_encode($map).json_encode($data));
- ksort ($map);
- $weibopay = new Weibopay ();
- error_log( date ( "[YmdHis]" ) ."\t" . json_encode($map). json_encode($data). "\r\n", 3, '../'. date ( "Y-m-d" ) . '.log10' );
- if ($weibopay->checkSignMsg ($map,@$map ["sign_type"] )) {
- switch ($map["notify_type"])
- {
- //交易结果通知
- case "trade_status_sync":
- //投标代收
- if($data['call']=='registercreditor'){
- require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');
- registercreditor_status_sync($map);
- }
- if($data['call']=='dotrtrade'){
- error_log( date ( "[YmdHis]" ) ."\t" . json_encode($map). "\r\n",4, '../'. date ( "Y-m-d" ) . '.log4' );
- require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');
- dotrtrade_status_sync($map);
- }
- if($data['call']=='dohktrade'){
- error_log( date ( "[YmdHis]" ) ."\t" . json_encode($map). "\r\n", 5, '../'. date ( "Y-m-d" ) . '.log41' );
- require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');
- dohktrade_status_sync($map);
- }
- //按照自己的业务需求获取对应参数进行保存
- // $weibopay->write_log("获取到trade_status_sync结果通知:时间:".date("YmdHis"));
- // $weibopay->write_log("获取到trade_status_sync结果通知:单号:".json_encode($_REQUEST));
- break;
- //交易退款结果通知
- case "refund_status_sync":
- //按照自己的业务需求获取对应参数进行保存
- $weibopay->write_log("获取到refund_status_sync结果通知:时间:".date("YmdHis"));
- $weibopay->write_log("获取到refund_status_sync结果通知:单号:".json_encode($_REQUEST));
- break;
- //充值结果通知
- case "deposit_status_sync":
- //done
- require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');
- deposit_status_sync($map);
- break;
- //提现结果通知
- case "withdraw_status_sync":
- $weibopay->write_log("获取到batch_trade_status_sync结果通知:时间:".date("YmdHis"));
- $weibopay->write_log("获取到batch_trade_status_sync结果通知:单号:".json_encode($_REQUEST));
- require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');
- withdraw_status_sync($map);
- break;
- //批量代付结果通知
- case "batch_trade_status_sync":
- //按照自己的业务需求获取对应参数进行保存
- $weibopay->write_log("获取到batch_trade_status_sync结果通知:时间:".date("YmdHis"));
- $weibopay->write_log("获取到batch_trade_status_sync结果通知:单号:".json_encode($_REQUEST));
- break;
- //审核结果通知
- case "audit_status_sync":
- require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');
- audit_status_sync($map);
- //按照自己的业务需求获取对应参数进行保存
- $weibopay->write_log("获取到audit_status_sync结果通知:时间:".date("YmdHis"));
- $weibopay->write_log("获取到audit_status_sync结果通知:单号:".json_encode($_REQUEST));
- break;
- default:
- $weibopay->write_log("获取到未知结果通知:时间:".date("YmdHis"));
- $weibopay->write_log("获取到未知结果通知:单号:".json_encode($_REQUEST));
- echo "通知类型错误!";
- }
- // 如果回调成功,需要输出SUCCESS告知新浪回调服务器,已经收到异步通知。
- echo 'success';
- } else {
- $msg="签名错误 or 非法请求";
- $weibopay->write_log($msg);
- die ( "sign error" );
- }
- }
- //资质提价
四,打开 system/collocation/sina/SinaNotify.php 文件,充值回调。
- if($map['trade_status']=='PAY_FINISHED'){
- $pErrCode = 'MG00000F';
- $data['pErrCode'] ='MG00000F';
- $data['pErrMsg'] = 'MG00000F';;
- }
五,成功之后进行下面的操作。
Tags: 接口 新浪 笔记
- 上一篇:PHP使用pdo实现事务处理操作示例
- 下一篇:php版新浪支付接口之新建接口笔记
相关文章
- ·ArrayAccess接口介绍(2014-01-14)
- ·php中实现api接口思路介绍(2014-02-10)
- ·php版淘宝网查询商品接口代码(2014-06-17)
- ·PHP实现百度、网易、新浪短网址服务的API接口调用(2014-06-27)
- ·ip地址api第三方jsonp接口整理(2014-07-01)
- ·淘宝IP地址库API接口(PHP)通过ip获取地址信息(2014-07-02)
- ·微信公众平台消息接口(PHP)-官方的Demo有问题(2014-07-29)
- ·php数组 类和对象 接口使用方法(2014-09-08)
- ·php 支付宝接口程序源码(2014-09-09)
- ·php飞信接口实例应用代码(2014-09-09)
- ·php google api 接口程序(2014-09-10)
- ·微信公众平台的开发接口简单例子(2014-09-21)
- ·php新浪微博登录接口实例代码(2014-09-22)
- ·微信公众平台消息接口校验与消息接口响应例子(2014-09-22)
- ·php天翼开放平台短信发送接口实现(2014-09-22)
- ·开发微信公众平台接口参数调试-判断用户行为(2014-09-22)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)