72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Constants\HttpEnumCode;
|
|
use App\Exception\BusinessException;
|
|
use App\Services\BaseService;
|
|
use App\Utils\Log;
|
|
use Extend\Wechat\WechatPay;
|
|
use Hyperf\HttpMessage\Stream\SwooleFileStream;
|
|
use Hyperf\HttpMessage\Stream\SwooleStream;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
class CallBackController extends AbstractController
|
|
{
|
|
/**
|
|
* 患者端微信支付回调
|
|
* @return ResponseInterface
|
|
* @throws \Throwable
|
|
*/
|
|
public function patientWxPayCallBack(): ResponseInterface
|
|
{
|
|
dump(111);
|
|
try {
|
|
// 处理支付结果事件
|
|
$WechatPay = new WechatPay(1);
|
|
$app = $WechatPay->createApp();
|
|
$server = $app->getServer();
|
|
|
|
$message = $server->getRequestMessage();
|
|
if (empty($message)){
|
|
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
|
}
|
|
|
|
dump($message);
|
|
|
|
|
|
return $server->serve();
|
|
}catch (\Exception $e) {
|
|
throw new BusinessException($e->getMessage());
|
|
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => $e->getMessage()], JSON_UNESCAPED_UNICODE))));
|
|
}
|
|
}
|
|
|
|
// 医生端微信支付回调
|
|
public function doctorWxPayCallBack(): ResponseInterface
|
|
{
|
|
$request_params = $this->request->all();
|
|
dump($request_params);
|
|
try {
|
|
// 处理支付结果事件
|
|
$WechatPay = new WechatPay(2);
|
|
$app = $WechatPay->createApp();
|
|
$server = $app->getServer();
|
|
|
|
$message = $server->getDecryptedMessage()->toArray();
|
|
|
|
dump($message);
|
|
|
|
return $server->serve();
|
|
}catch (\Exception $e) {
|
|
throw new BusinessException($e->getMessage());
|
|
// return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => $e->getMessage()], JSON_UNESCAPED_UNICODE))));
|
|
}
|
|
}
|
|
|
|
// im回调
|
|
public function imCallBack(){
|
|
$request_params = $this->request->all();
|
|
Log::getInstance()->info(json_encode($request_params,JSON_UNESCAPED_UNICODE));
|
|
}
|
|
} |