新浪支付接口开发与支付宝的差不多先是按官方的要求提交数据然后再把支付成功的信息反馈过来给用户,这样就实现了支付及成功的提示了。
所谓的新浪回调接口,就是当资金充值成功之后,新浪会通知本网站一个信息来告知已经充值成功,并返回一组成功的数组,我们根据这些数据再进行一个本地数据库的同步操作,比如更新本地数据库是否充值成功的状态,由未支付改为已支付,然后再网站上面进行显示,还有资金也会进行同步 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';;
}
五,成功之后进行下面的操作。