純PHP代碼實現支付寶批量付款_php執行個體

來源:互聯網
上載者:User

最近在做一個使用支付寶轉賬的項目,其中有需求把我難到了:批量支付成功後不知道怎麼接收系統返回的通知,經過朋友幫忙,此功能實現,下面小編把具體代碼整理分享給大家,供大家參考

廢話不多說了,直接給大家貼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代碼實現支付寶批量付款的功能,希望對大家有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.