PayController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Http\Controllers\V1;
  3. use App\Models\UserMemberOrder;
  4. use Illuminate\Http\Request;
  5. use Alipay\EasySDK\Kernel\Factory;
  6. use Alipay\EasySDK\Kernel\Util\ResponseChecker;
  7. use Alipay\EasySDK\Kernel\Config;
  8. /**
  9. * 支付
  10. */
  11. class PayController extends Controller
  12. {
  13. public function __construct()
  14. {
  15. $this->user = auth('api')->user();
  16. $this->userId = $this->user ? $this->user->id : 0;
  17. //如果用户被删除,会自动退出登录
  18. if (!empty($this->user->deleted_at)) {
  19. $this->user->online = 0;
  20. $this->user->save();
  21. auth('api')->logout();
  22. }
  23. Factory::setOptions($this->getOptions());
  24. }
  25. public function getOptions(){
  26. $options = new Config();
  27. $options->protocol = 'https';
  28. $options->gatewayHost = 'openapi.alipay.com';
  29. $options->signType = 'RSA2';
  30. $options->appId = '2016082201783461';
  31. $options->merchantPrivateKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6x0l1piPwoCObHcvkViykIsY+D8FJ5Cqvr0sUkpFgQpy9Mt/0zkA0gnWBDS3OtZl2QYuwKuooBrexa+Snbpd+SsTLGWtTieIt3xhtctigtw3j88HbiEZ/J/yDYCgHjgMCWglhYUOVMfnOFNqRTFhbSioKX1atmKLZvKR/iFFH5Sp9lIZUrutFvbB6fyyKqx4IdTc7ZxEBuwYZafuUSe6h4mYtQvPMPfbPX3+N0wLlhYjeiUMJiDC5x+V7CVP6muxuEKzBWsDyl8lP7bwfyAuaVlCX0QvsdNyTLwU/g2fagyHMg0Yd1rJnW/LWCp8OcKc0S2Q2NTCRut72i4jEU0bFwIDAQAB';
  32. $options->alipayPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjkCziKKZaCde/Wyf29S7Z/lvVLcecLQzJa2V6EGCsBbN8GA/kF7dnHPbzps32eurMIysvmhhulAd+D3O/580lQh6cmcUVc3EZ01lfq2Ki+jM2B8EVTyegqS9ADsIVGa//1hJ7i2J2ulgD1Ros5WBZ8rebsd6Qhq/0uJeOksEFA/Fxv209yp+gKnidUozX7ACDalqHp38OeRw0YWRRICyKh1pPkW7n+hj2GElIBPZUc9SWPkNIkCHwExjV1ha6BkrdiBeLrkKjgh1ul6rTG7AeQdtW54nOWmt7caNJ/swnA7zi8n9j/FAzF9tz4mflVCvdOZYO0PCs+Gea4QVYh2X3wIDAQAB';
  33. // $options->notifyUrl = ''
  34. return $options;
  35. }
  36. /**
  37. * @return void
  38. * 构建支付
  39. */
  40. public function payment(Request $request){
  41. $order_id = $request->get('order_id');
  42. $pay_type = $request->get('pay_type');
  43. if(!$order_id || !$pay_type){
  44. return $this->error("缺少参数!");
  45. }
  46. $order = UserMemberOrder::query()->where('id',$order_id)->first();
  47. if(!$order){
  48. return $this->error("订单不存在!");
  49. }
  50. $result = Factory::payment()->common()->create("加入企业会员",$order->order_no,0.01,1);
  51. dd($result);
  52. }
  53. }