This commit is contained in:
2023-03-06 15:44:21 +08:00
parent 22071904fe
commit 81d64710fd
8 changed files with 136 additions and 18 deletions
+21
View File
@@ -9,7 +9,9 @@ use App\Services\UserDoctorService;
use App\Services\UserService;
use App\Utils\Http;
use Extend\Wechat\Wechat;
use Extend\Wechat\WechatPay;
use Hyperf\DbConnection\Db;
use Hyperf\Snowflake\IdGeneratorInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
@@ -65,4 +67,23 @@ class UserController extends AbstractController
$data = $UserService->putLoginout();
return $this->response->json($data);
}
// 支付测试
public function testpay(){
$generator = $this->container->get(IdGeneratorInterface::class);
$WechatPay = new WechatPay(2);
// 获取预支付交易会话标识
$total = 0.01 * 100;
$prepay = $WechatPay->getJsapiPrepayId("123456",$total,"o9gYG441zEAHuYoNX7lwFKiQBzKE");
if (empty($prepay)){
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
}
// 获取小程序支付配置
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
return $this->response->json($pay_config);
}
}