You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
3.1 KiB

7 years ago
  1. <?php
  2. namespace App\Common;
  3. class Payment
  4. {
  5. //微信APP支付
  6. public static function WeixinPayApp($attributes2,$config = config('weixin.app'))
  7. {
  8. //1.配置
  9. //$config = config('weixin.app');
  10. $app = new \EasyWeChat\Foundation\Application($config);
  11. $payment = $app->payment;
  12. //2.创建订单
  13. $attributes = array(
  14. 'trade_type' => 'APP', // JSAPI,NATIVE,APP...
  15. 'body' => '订单支付',
  16. 'detail' => '订单支付',
  17. 'out_trade_no' => 'fghfdgfg789',
  18. 'total_fee' => '123.00', // 单位:分
  19. 'notify_url' => 'http://www.baidu.com/aaa.php', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  20. //'openid' => '当前用户的 openid', // trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识,
  21. // ...
  22. );
  23. $order = new \EasyWeChat\Payment\Order(array_merge($attributes, $attributes2));
  24. //3.统一下单
  25. $result = $payment->prepare($order);
  26. if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS')
  27. {
  28. $prepayId = $result->prepay_id;
  29. $res = $payment->configForAppPayment($prepayId);
  30. return $res;
  31. }
  32. return false;
  33. }
  34. /**
  35. * 支付宝APP支付
  36. * bizcontent
  37. * 支付宝APP支付
  38. */
  39. public function AlipayApp($bizcontent,$notify_url,$config = config('alipay.app_alipay'))
  40. {
  41. require_once base_path('resources/org/alipay_app').'/AopClient.php';
  42. require_once base_path('resources/org/alipay_app').'/AlipayTradeAppPayRequest.php';
  43. $aop = new \AopClient;
  44. $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
  45. $aop->appId = $config['appId'];
  46. $aop->rsaPrivateKey = $config['rsaPrivateKey'];
  47. $aop->format = "json";
  48. $aop->charset = "UTF-8";
  49. $aop->signType = "RSA2";
  50. $aop->alipayrsaPublicKey = $config['alipayrsaPublicKey'];
  51. //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
  52. $request = new \AlipayTradeAppPayRequest();
  53. //SDK已经封装掉了公共参数,这里只需要传入业务参数
  54. /* $bizcontent = "{\"body\":\"订单支付\","
  55. . "\"subject\": \"订单支付\","
  56. . "\"out_trade_no\": \""."jklkjlkj54654165"."\","
  57. . "\"total_amount\": \""."123.00"."\","
  58. . "\"timeout_express\": \"30m\","
  59. . "\"product_code\":\"QUICK_MSECURITY_PAY\""
  60. . "}"; */
  61. $request->setNotifyUrl($notify_url);
  62. $request->setBizContent($bizcontent);
  63. //这里和普通的接口调用不同,使用的是sdkExecute
  64. $response = $aop->sdkExecute($request);
  65. //htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题
  66. return $response;//就是orderString 可以直接给客户端请求,无需再做处理。
  67. }
  68. }