RenewController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace open\controllers;
  3. use biz\saas\services\RenewService;
  4. use biz\saas\services\SetMealService;
  5. use common\components\configDict;
  6. use common\components\util;
  7. use Yii;
  8. class RenewController extends BaseController
  9. {
  10. //微信支付 shish 2019.12.23
  11. public function actionWxPay()
  12. {
  13. ini_set('date.timezone', 'Asia/Shanghai');
  14. $setId = Yii::$app->request->get('setId', 1);
  15. $set = SetMealService::getById($setId);
  16. if (empty($set)) {
  17. util::fail('没有找到套餐');
  18. }
  19. $post['userId'] = $this->userId;
  20. $price = $set['price'];
  21. $post['prePrice'] = $price;
  22. $post['actPrice'] = $price;
  23. $post['payWay'] = 0;
  24. $now = time();
  25. $expireTime = $now + 300;//订单5分钟后过期
  26. $post['createTime'] = date("Y-m-d H:i:s", $now);
  27. $post['deadline'] = $expireTime;
  28. $renew = RenewService::add($post);
  29. $orderId = $renew['orderSn'];
  30. $name = $set['name'] . '购买续费';
  31. $totalFee = $price;
  32. $user = $this->user;
  33. $openId = $user['openId'];
  34. $typeList = configDict::getConfig('capitalType');
  35. $capitalType = $typeList['xhOrder']['id'];
  36. $attach = 'capitalType=' . $capitalType . '&couponId=0';//将流水类型、优惠卷传过去
  37. $wx = Yii::getAlias("@vendor/weixin");
  38. require_once($wx . '/lib/WxPay.Api.php');
  39. require_once($wx . '/example/WxPay.JsApiPay.php');
  40. $input = new \WxPayUnifiedOrder();
  41. $input->SetBody($name);
  42. $input->SetOut_trade_no($orderId);
  43. $input->SetTotal_fee($totalFee * 100);
  44. $input->SetTime_start(date("YmdHis", $now));
  45. $input->SetAttach($attach);
  46. $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟
  47. $input->SetNotify_url($this->frontUrl . '/notice/weixin-callback/');
  48. $input->SetTrade_type("JSAPI");
  49. //花卉宝代为申请的微信支付
  50. $merchantExtend = $this->merchantExtend;
  51. if ($merchantExtend['generalMerchant'] == 1) {
  52. $input->SetSub_openid($openId);
  53. } else {
  54. $input->SetOpenid($openId);
  55. }
  56. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  57. $tools = new \JsApiPay();
  58. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  59. $newParams = json_decode($jsApiParameters, true);
  60. $newParams['orderId'] = $orderId;
  61. util::success($newParams);
  62. }
  63. }