最近在做一个使用支付宝转账的项目,其中有需求把我难到了:批量支付成功后不知道怎么接收系统返回的通知,经过朋友帮忙,此功能实现,下面小编把具体代码整理分享给大家,供大家参考
废话不多说了,直接给大家贴php代码了,具体代码如下所示:
//批量付款异步通知处理
class notify
{
public $notifyparams;
//处理成功的信息
protected $success = [];
//处理失败的信息
protected $fail = [];
//批次号
protected $batchno;
public function save()
{
if (!is_array($this->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';
以上内容给大家讲解了纯php代码实现支付宝批量付款的功能,希望对大家有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!