当前位置:首页 > PHP教程 > php高级应用 > 列表

php版新浪支付接口之回调接口笔记

发布:smiling 来源: PHP粉丝网  添加日期:2018-09-14 11:17:58 浏览: 评论:0 

所谓的新浪回调接口,就是当资金充值成功之后,新浪会通知本网站一个信息来告知已经充值成功,并返回一组成功的数组,我们根据这些数据再进行一个本地数据库的同步操作,比如更新本地数据库是否充值成功的状态,由未支付改为已支付,然后再网站上面进行显示,还有资金也会进行同步 update,好了,下面夏日博客把日志分享下来,接着上一篇新浪支付新建接口,一个简单的新浪支付回调接口,这个异步回调的信息是通过日志生成到ftp下面的,根据日志进行本地的更新。

一,先查看日志文件

说明:数据提交到新浪之后会生成新浪日志文件,如下:

  1. {"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 方法,方法如下:

  1. public function response_sina()  {    
  2.      $content=  $_REQUEST;   
  3.     error_logdate ( "[YmdHis]" ) ."\t" . json_encode($content) . "\r\n", 3, '../'date ( "Y-m-d" ) . '.log1' );   
  4.     $class_name = getCollName();   
  5.     require_once APP_ROOT_PATH."system/collocation/".$class_name."_collocation.php";   
  6.     $collocation_class = $class_name."_collocation";   
  7.     $collocation_object = new $collocation_class();   
  8.     $collocation_code = $collocation_object->SinaNotify($_POST,$_REQUEST);    
  9. }  

三,打开 system/collocation/Sina_collocation.php 文件,查找 SinaNotify 方法,如下:

  1. function SinaNotify($map,$data){   
  2.        // $weibopay->write_log("获取到refund_status_sync结果通知:单号:".json_encode($map).json_encode($data));   
  3.         ksort ($map);    
  4.         $weibopay = new Weibopay ();   
  5.         error_logdate ( "[YmdHis]" ) ."\t" . json_encode($map).  json_encode($data). "\r\n", 3, '../'date ( "Y-m-d" ) . '.log10' );   
  6.         if ($weibopay->checkSignMsg ($map,@$map ["sign_type"] )) {   
  7.             switch ($map["notify_type"])   
  8.             {       
  9.                 //交易结果通知   
  10.                 case "trade_status_sync":   
  11.                     //投标代收   
  12.                       
  13.                     if($data['call']=='registercreditor'){   
  14.                          
  15.                         require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');   
  16.                             
  17.                          registercreditor_status_sync($map);   
  18.                            
  19.                            
  20.                            
  21.                     }    
  22.                     if($data['call']=='dotrtrade'){   
  23.                         
  24.                         error_logdate ( "[YmdHis]" ) ."\t" . json_encode($map). "\r\n",4, '../'date ( "Y-m-d" ) . '.log4' );   
  25.                         require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');   
  26.                        
  27.                          dotrtrade_status_sync($map);   
  28.                             
  29.                             
  30.                             
  31.                     }   
  32.                     if($data['call']=='dohktrade'){   
  33.                        
  34.                         error_logdate ( "[YmdHis]" ) ."\t" . json_encode($map). "\r\n", 5, '../'date ( "Y-m-d" ) . '.log41' );   
  35.                         require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');   
  36.                             
  37.                          dohktrade_status_sync($map);   
  38.                        
  39.                        
  40.                        
  41.                     }   
  42.                        
  43.                        
  44.                     //按照自己的业务需求获取对应参数进行保存   
  45.                   //  $weibopay->write_log("获取到trade_status_sync结果通知:时间:".date("YmdHis"));   
  46.                    // $weibopay->write_log("获取到trade_status_sync结果通知:单号:".json_encode($_REQUEST));   
  47.                     break;   
  48.                     //交易退款结果通知   
  49.                 case "refund_status_sync":   
  50.                     //按照自己的业务需求获取对应参数进行保存   
  51.                     $weibopay->write_log("获取到refund_status_sync结果通知:时间:".date("YmdHis"));   
  52.                     $weibopay->write_log("获取到refund_status_sync结果通知:单号:".json_encode($_REQUEST));   
  53.                     break;   
  54.                     //充值结果通知   
  55.                 case "deposit_status_sync":   
  56.                     //done   
  57.                     require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');   
  58.                        
  59.                      deposit_status_sync($map);   
  60.                
  61.                     break;   
  62.                     //提现结果通知   
  63.                 case "withdraw_status_sync":   
  64.                     $weibopay->write_log("获取到batch_trade_status_sync结果通知:时间:".date("YmdHis"));   
  65.                     $weibopay->write_log("获取到batch_trade_status_sync结果通知:单号:".json_encode($_REQUEST));   
  66.                     require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');   
  67.                         
  68.                      withdraw_status_sync($map);   
  69.                    
  70.                     break;   
  71.                     //批量代付结果通知   
  72.                 case "batch_trade_status_sync":   
  73.                     //按照自己的业务需求获取对应参数进行保存   
  74.                     $weibopay->write_log("获取到batch_trade_status_sync结果通知:时间:".date("YmdHis"));   
  75.                     $weibopay->write_log("获取到batch_trade_status_sync结果通知:单号:".json_encode($_REQUEST));   
  76.                     break;   
  77.                     //审核结果通知   
  78.                 case "audit_status_sync":   
  79.                     require_once(APP_ROOT_PATH.'system/collocation/sina/SinaNotify.php');   
  80.                        
  81.                     audit_status_sync($map);   
  82.                     //按照自己的业务需求获取对应参数进行保存   
  83.                     $weibopay->write_log("获取到audit_status_sync结果通知:时间:".date("YmdHis"));   
  84.                     $weibopay->write_log("获取到audit_status_sync结果通知:单号:".json_encode($_REQUEST));   
  85.                     break;   
  86.                 default:   
  87.                     $weibopay->write_log("获取到未知结果通知:时间:".date("YmdHis"));   
  88.                     $weibopay->write_log("获取到未知结果通知:单号:".json_encode($_REQUEST));   
  89.                     echo "通知类型错误!";   
  90.             }   
  91.             // 如果回调成功,需要输出SUCCESS告知新浪回调服务器,已经收到异步通知。   
  92.             echo 'success';   
  93.         } else {   
  94.             $msg="签名错误 or 非法请求";   
  95.             $weibopay->write_log($msg);   
  96.             die ( "sign error" );   
  97.         }   
  98.     }   
  99.     //资质提价   

四,打开 system/collocation/sina/SinaNotify.php 文件,充值回调。

  1. if($map['trade_status']=='PAY_FINISHED'){   
  2.             $pErrCode = 'MG00000F';   
  3.             $data['pErrCode'] ='MG00000F';   
  4.             $data['pErrMsg'] = 'MG00000F';;   
  5.         }   

五,成功之后进行下面的操作。

Tags: 接口 新浪 笔记

分享到: