src/AppBundle/Controller/Cashier/WechatController.php

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace AppBundle\Controller\Cashier;

use ApiBundle\Api\ApiRequest;
use AppBundle\Component\Payment\Wxpay\JsApiPay;
use Symfony\Component\HttpFoundation\Request;

class WechatController extends PaymentController
{
    public function wechatJsPayAction(Request $request)
    {
        if (!$request->query->get('code', '')) {
            $request->getSession()->set('wechat_pay_params', $request->query->all());
        }

        $user = $this->getUser();

        if (!$user->isLogin()) {
            return $this->createMessageResponse('error', '用户未登录,支付失败。');
        }

        try {
            $biz = $this->getBiz();

            $options = $biz['payment.platforms.options']['wechat'];

            $jsApi = new JsApiPay(array(
                'appid' => $options['appid'],
                'account' => $options['mch_id'],
                'key' => $options['key'],
                'secret' => $options['secret'],
                'redirect_uri' => $this->generateUrl('cashier_wechat_js_pay', array(), true),
                'isMicroMessenger' => true,
            ), $request);

            $openid = $jsApi->getOpenid();
        } catch (\Exception $e) {
            return $this->createMessageResponse('error', '不能使用微信支付,可能是网校未开启微信支付或配置不正确');
        }

        $params = $request->getSession()->get('wechat_pay_params');
        $apiKernel = $this->get('api_resource_kernel');
        $apiRequest = new ApiRequest(
            '/api/trades',
            'POST',
            array(),
            array(
                'gateway' => 'WechatPay_Js',
                'type' => empty($params['type']) ? 'purchase' : $params['type'],
                'openid' => $openid,
                'orderSn' => empty($params['orderSn']) ? '' : $params['orderSn'],
                'coinAmount' => empty($params['coinAmount']) ? 0 : $params['coinAmount'],
                'amount' => empty($params['amount']) ? 0 : $params['amount'],
                'unencryptedPayPassword' => empty($params['payPassword']) ? '' : $params['payPassword'],
            ),
            array()
        );

        $result = $apiKernel->handleApiRequest($apiRequest);

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。