CodeSciencePayController.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/3/30
  8. * Time: 17:58
  9. */
  10. namespace app\payment\controllers;
  11. use app\common\models\PayOrder;
  12. use app\common\models\PayType;
  13. use app\payment\PaymentController;
  14. use Yunshop\CodeSciencePay\services\CodeSciencePay;
  15. class CodeSciencePayController extends PaymentController
  16. {
  17. const PAY_ID = 99;
  18. public function notifyUrl()
  19. {
  20. $data = json_decode(request()->getContent(), true);
  21. \Log::debug(self::class. '--接收回调: ' . $data);
  22. $payOrder = PayOrder::where('out_order_no', $data['data']['orderid'])->first();
  23. if (!$payOrder) {
  24. \Log::debug(self::class. '--: 未找到支付订单');
  25. return;
  26. }
  27. \YunShop::app()->uniacid = $payOrder->uniacid;
  28. \Setting::$uniqueAccountId = $payOrder->uniacid;
  29. $codeSciencePay = new CodeSciencePay;
  30. $codeSciencePay->reqData = $data;
  31. try {
  32. $res = $codeSciencePay->verify();
  33. } catch (\Exception $e) {
  34. \Log::debug(self::class. '--验签失败 失败原因: ' . $e->getMessage());
  35. $res = false;
  36. }
  37. if (!$res) {
  38. \Log::debug(self::class. '--: 验签失败');
  39. return;
  40. }
  41. $currentPayType = $this->currentPayType(self::PAY_ID);
  42. $data = $this->setData($data['data']['orderid'], $data['data']['orderid'], $data['amount'], $currentPayType['id'], $currentPayType['name']);
  43. $this->payResutl($data);
  44. \Log::debug(self::class . '订单支付成功--订单号: ' . $data['data']['orderid']);
  45. return json_encode([
  46. 'result' => '0000',
  47. 'resultdesc' => '成功'
  48. ]);
  49. }
  50. /**
  51. * 支付回调参数
  52. *
  53. * @param $order_no
  54. * @param $parameter
  55. * @return array
  56. */
  57. public function setData($order_no, $trade_no, $total_fee, $pay_type_id, $pay_type)
  58. {
  59. return [
  60. 'total_fee' => $total_fee,
  61. 'out_trade_no' => $order_no,
  62. 'trade_no' => $trade_no,
  63. 'unit' => 'fen',
  64. 'pay_type' => $pay_type,
  65. 'pay_type_id' => $pay_type_id,
  66. ];
  67. }
  68. public function currentPayType($payId)
  69. {
  70. return PayType::find($payId);
  71. }
  72. }