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

2025-05-29 0 106

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

废话不多说了,直接给大家贴php代码了,具体代码如下所示:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62
//批量付款异步通知处理

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代码实现支付宝批量付款的功能,希望对大家有所帮助。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 纯PHP代码实现支付宝批量付款 https://www.kuaiidc.com/99102.html

相关文章

发表评论
暂无评论