Pure PHP code to implement Alipay batch payment, _PHP tutorial

WBOY
Release: 2016-07-12 09:02:48
Original
785 people have browsed it

Pure PHP code to implement Alipay batch payment,

I am currently working on a project using Alipay to transfer money, and there is a demand that makes it difficult for me: I don’t know how to receive the system after the batch payment is successful. Return notification, with the help of friends, this function was implemented. Below, the editor will organize and share the specific code with everyone for your reference

Without further ado, I will just post the php code 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';
Copy after login

The above content explains to you the function of realizing Alipay batch payment with pure PHP code. I hope it will be helpful to you.

Articles you may be interested in:

  • Alipay interface development help (asp, php, asp.net, jsp)
  • php modify zen-cart order and payment process To prevent missing orders
  • ThinkPHP implements Alipay interface function example
  • php analyzes the difference between return_url and notify_url in Alipay development
  • php Alipay interface usage analysis
  • php Alipay mobile web payment class example

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084545.htmlTechArticlePure PHP code to implement Alipay batch payment. I am currently working on a project using Alipay to transfer money. There are demands that make it difficult for me. Here it is: I don’t know how to receive the response from the system after the batch payment is successful...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template