最近在做一个使用支付宝转账的项目,其中有需求把我难到了:批量支付成功后不知道怎么接收系统返回的通知,经过朋友帮忙,此功能实现,下面小编把具体代码整理分享给大家,供大家参考
notifyParams)) {
return false;
}
$alipayNotify = new AlipayNotify();
$alipayNotify->notifyParams = $this->notifyParams;
$alipayNotify->partner = Yii::$app->params['Alipay.appid'];
$alipayNotify->key = Yii::$app->params['Alipay.appKey'];
if (!$alipayNotify->verify()) {
return false;
}
$this->batchNo = $this->notifyParams['batch_no'];
$this->parseResult();
//转账成功的
if (!empty($this->success)) {
foreach ($this->success as $item) {
//.........
}
}
//转账失败的
if (!empty($this->fail)) {
foreach ($this->fail as $item) {
//........
}
}
return true;
}
//解析结果
protected function parseResult()
{
if (!empty($this->notifyParams['success_details'])) {
$suArray = explode('|',$this->notifyParams['success_details']);
foreach ($suArray as $item) {
$this->success[] = explode('^',$item);
}
}
if (!empty($this->notifyParams['fail_detail'])) {
$faArray = explode('|',$this->notifyParams['fail_detail']);
foreach ($faArray as $item) {
$this->fail[] = explode('^',$item);
}
}
}
}
//用法
$model = new Notify();
$model->notifyParams = $_POST;
if ($model->save()) {
return 'success';
}
return 'fail';