Home > php教程 > php手册 > body text

纯PHP代码实现支付宝批量付款,

WBOY
Release: 2016-06-13 08:49:10
Original
1108 people have browsed it

纯PHP代码实现支付宝批量付款,

最近在做一个使用支付宝转账的项目,其中有需求把我难到了:批量支付成功后不知道怎么接收系统返回的通知,经过朋友帮忙,此功能实现,下面小编把具体代码整理分享给大家,供大家参考

废话不多说了,直接给大家贴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';
Copy after login

以上内容给大家讲解了纯PHP代码实现支付宝批量付款的功能,希望对大家有所帮助。

您可能感兴趣的文章:

  • 支付宝 接口开发帮助(asp,php,asp.net,jsp)
  • php 修改zen-cart下单和付款流程以防止漏单
  • ThinkPHP实现支付宝接口功能实例
  • php进行支付宝开发中return_url和notify_url的区别分析
  • php支付宝接口用法分析
  • php支付宝手机网页支付类实例
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!