Recently I am working on a project using Alipay to transfer money. There is a requirement that makes me difficult: I don’t know how to receive the notification returned by the system after the batch payment is successful. With the help of a friend, this function is implemented. The editor will organize and share the specific code with you below. , for your reference
No more nonsense, I will post the PHP code directly for you. The specific code is as follows:
//批量付款异步通知处理 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';
The above content explains to you the function of realizing Alipay batch payment with pure PHP code. I hope it will be helpful to everyone. Helps.
The above introduces the pure PHP code to implement Alipay batch payment, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.