diff --git a/app/Controller/CallBackController.php b/app/Controller/CallBackController.php index 2a1f203..86fcb4a 100644 --- a/app/Controller/CallBackController.php +++ b/app/Controller/CallBackController.php @@ -20,7 +20,6 @@ class CallBackController extends AbstractController */ public function patientWxPayCallBack(): ResponseInterface { - dump(111); try { // 处理支付结果事件 $WechatPay = new WechatPay(1); diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index a663cb4..a2bbd33 100644 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -70,13 +70,14 @@ class UserController extends AbstractController // 支付测试 public function testpay(){ + $out_trade_no = $this->request->input('out_trade_no'); $generator = $this->container->get(IdGeneratorInterface::class); $WechatPay = new WechatPay(2); // 获取预支付交易会话标识 $total = 0.01 * 100; - $prepay = $WechatPay->getJsapiPrepayId("123468",$total,"o9gYG441zEAHuYoNX7lwFKiQBzKE"); + $prepay = $WechatPay->getJsapiPrepayId($out_trade_no,$total,"o9gYG441zEAHuYoNX7lwFKiQBzKE"); if (empty($prepay)){ return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败"); } diff --git a/extend/Wechat/WechatPay.php b/extend/Wechat/WechatPay.php index 04a96e4..60b0ce0 100644 --- a/extend/Wechat/WechatPay.php +++ b/extend/Wechat/WechatPay.php @@ -8,7 +8,10 @@ use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; use EasyWeChat\Kernel\Exceptions\InvalidConfigException; use EasyWeChat\OfficialAccount\Message; use EasyWeChat\Pay\Application; +use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\Utils\ApplicationContext; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use Psr\SimpleCache\CacheInterface; /** @@ -42,6 +45,8 @@ class WechatPay /** * 创建工厂类 * @return Application + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function createApp(): Application { @@ -77,7 +82,10 @@ class WechatPay ]; try { - return new Application($config); + $app = new Application($config); + $request = ApplicationContext::getContainer()->get(RequestInterface::class); + $app->setRequest($request); + return $app; } catch (InvalidArgumentException $e) { throw new BusinessException('实例化EasyWeChat类失败:' . $e->getMessage(), HttpEnumCode::SERVER_ERROR); }