Demo.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * 支付宝插件Demo
  4. * @author Jack_YanTC <627495692@qq.com>
  5. */
  6. class Demo {
  7. function __construct(){
  8. $config['appId']='135';
  9. $config['rsaPrivateKey']='135';
  10. $config['signType']='135';
  11. $config['alipayrsaPublicKey']='135';
  12. $this -> config = $config;
  13. }
  14. public function index() {
  15. $data['body']='订单详情';
  16. $data['subject']='订单';
  17. $data['out_trade_no']='201705201314';
  18. $data['total_amount']='0.01';
  19. require_once("./Plugins/AliPay/AliPay.php");
  20. //可传入$options自己的appid
  21. //$alipay =new \AliPay($this -> config);
  22. //配置到config的话,不许传递参数
  23. $alipay =new \AliPay();
  24. $result['app'] =$alipay->AliPayApp($data);
  25. $result['web'] =$alipay->AliPayWeb($data);
  26. $result['check']=$alipay->AliPayNotifyCheck();
  27. p($result['web']);
  28. //jsonReturn(0, 1, $result);
  29. }
  30. //app支付 示例
  31. public function appPay() {
  32. $data['body']='订单详情';
  33. $data['subject']='订单';
  34. $data['out_trade_no']='201705201314';
  35. $data['total_amount']='0.01';
  36. require_once("Plugins/AliPay/AliPay.php");
  37. $alipay =new \AliPay();
  38. $result =$alipay->AliPayApp($data);
  39. return $result;
  40. }
  41. //web支付 示例
  42. public function webPay() {
  43. $data['body']='订单详情';
  44. $data['subject']='订单';
  45. $data['out_trade_no']='201705201314';
  46. $data['total_amount']='0.01';
  47. require_once("Plugins/AliPay/AliPay.php");
  48. $alipay =new \AliPay();
  49. $result =$alipay->AliPayWeb($data);
  50. return $result;
  51. }
  52. //移动web支付 示例
  53. public function mobileWebPay() {
  54. $data['body']='订单详情';
  55. $data['subject']='订单';
  56. $data['out_trade_no']='201705201314';
  57. $data['total_amount']='0.01';
  58. require_once("Plugins/AliPay/AliPay.php");
  59. $alipay =new \AliPay();
  60. $result =$alipay->AliPayMobileWeb($data);
  61. return $result;
  62. }
  63. //支付回调地址 示例
  64. public function alipayNotify() {
  65. require_once("Plugins/AliPay/AliPay.php");
  66. $alipay =new \AliPay();
  67. //验证是否是支付宝发送
  68. $flag=$alipay->AliPayNotifyCheck();
  69. if ($flag) {
  70. if ($_POST['trade_status'] == 'TRADE_FINISHED' || $_POST['trade_status'] == 'TRADE_SUCCESS') {
  71. $out_trade_no = trim($_POST['out_trade_no']); //商户订单号
  72. //成功后的业务逻辑处理
  73. $result = D('Common/Order')->notify($out_trade_no);
  74. if ($result) {
  75. echo "success"; //告诉支付宝支付成功
  76. die;
  77. }
  78. }
  79. }
  80. echo "fail"; //验证失败
  81. die;
  82. }
  83. //提现转账 示例
  84. public function withdraw() {
  85. $data['out_biz_no']='201705201314';//订单号
  86. $data['payee_account'] ='627495692@qq.com';//收款支付宝账号
  87. $data['payee_real_name'] ='颜廷超';//收款支付宝账号真实姓名
  88. $data['amount'] ='0.01';//金额
  89. $data['payer_show_name']='科技转账';
  90. $data['remark'] = '备注';
  91. require_once("Plugins/AliPay/AliPay.php");
  92. $alipay =new \AliPay();
  93. $result =$alipay->AliPayWithdraw($data);
  94. return $result;
  95. }
  96. }