最近在做一個使用支付寶轉帳的項目,其中有需求把我難到了:批量支付成功後不知道怎麼接收系統返回的通知,經過朋友幫忙,此功能實現,下面小編把具體代碼整理分享給大家,供大家參考
廢話不多說了,直接給大家貼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代碼實現支付寶批量付款的功能,希望對大家有所幫助。
以上就介紹了純PHP程式碼實現支付寶批量付款,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。