Pay.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Ems;
  5. use app\common\library\Sms;
  6. use fast\Random;
  7. use think\Config;
  8. use think\Validate;
  9. use think\Db;
  10. use wxpay;
  11. /**
  12. * 会员接口
  13. */
  14. class Pay extends Api
  15. {
  16. protected $noNeedLogin = ['notify'];
  17. protected $noNeedRight = '*';
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. if (!Config::get('fastadmin.usercenter')) {
  22. $this->error(__('User center already closed'));
  23. }
  24. }
  25. //二合一支付
  26. public function pay() {
  27. $user_token = input('user_token', '', 'trim');
  28. if (!$user_token) {
  29. $this->error('参数缺失');
  30. }
  31. //生成支付订单记录
  32. $rechar_order['user_id'] = $this->auth->id;
  33. $rechar_order['order_no'] = date('YmdHis', time()) . $this->auth->id . rand(10000000, 99999999); //微信订单编号
  34. $rechar_order['money'] = 49;
  35. $rechar_order['purpose'] = 3; //充值用途:1=支付订单,2=充值,3=开通会员
  36. $rechar_order['pay_type'] = 'zhuowang';
  37. $rechar_order['relation_id'] = 1;
  38. $rechar_order['createtime'] = time();
  39. //开始事务
  40. $result = Db::name('rechar_order')->insertGetId($rechar_order);
  41. if (!$result) {
  42. $this->error('网络延迟,请稍后再试');
  43. }
  44. $url = 'http://183.207.215.112:8090/HDC/3.0/hop/svc/pay/toPay.ajax';
  45. $data = [
  46. 'transId' => $rechar_order['order_no'],
  47. 'orderNo' => $rechar_order['order_no'],
  48. 'userToken' => $user_token,
  49. 'notifyUrl' => config('img_url') . '/api/pay/notify',
  50. 'backUrl' => config('back_url'),
  51. 'deskCode' => config('desk_code'),
  52. 'products' => [
  53. [
  54. 'productCode' => config('product_code'),
  55. 'productPrice' => '29',
  56. 'productUnit' => '连续包月',
  57. 'productCount' => 1
  58. ],
  59. [
  60. 'productCode' => config('product_code'),
  61. 'productPrice' => '199',
  62. 'productUnit' => '特惠包一年',
  63. 'productCount' => 1
  64. ],
  65. [
  66. 'productCode' => config('product_code'),
  67. 'productPrice' => '269',
  68. 'productUnit' => '特惠包两年',
  69. 'productCount' => 1
  70. ],
  71. ]
  72. ];
  73. $data = json_encode($data, 320);
  74. $header = [
  75. 'Host:112.4.10.122:8090',
  76. 'HDC-Service:2',
  77. 'HDC-APPID:00001',
  78. 'HDC-Token:8e2b129d2cd3ebf40ca5a1c6048b083ce92e5fd3f305fd6c11a3ef3e35b5fa08',
  79. 'Content-Type:application/json'
  80. ];
  81. $rs = httpRequest($url, 'POST', $data, $header);
  82. p($rs);
  83. }
  84. //支付回调
  85. public function notify() {
  86. }
  87. }