diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php index 0df0a89..098f35c 100644 --- a/app/Controller/TestController.php +++ b/app/Controller/TestController.php @@ -370,7 +370,33 @@ class TestController extends AbstractController } public function test_15(){ - $a = new Data(); - $a->product(); + $env_version = "release"; + $app_env = \Hyperf\Support\env("APP_ENV",'dev'); + if ($app_env == "dev"){ + $env_version = "trial"; + } + + $options = [ + "jump_wxa" => [ + "path" => "pages/expertDetail/expertDetail", + "query" => "doctor_id=539452507563012096", + "env_version" => $env_version, + ], + + "expire_type" => 1, + "expire_interval" => 1, + + ]; + + $Wechat = new Wechat(1); + $result = $Wechat->createUrlScheme($options); + dump($result); + + $options = [ + "scheme" => $result['openlink'] + ]; + + $result = $Wechat->getUrlScheme($options); + dump($result); } } \ No newline at end of file diff --git a/extend/Ca/Ca.php b/extend/Ca/Ca.php index 74476ad..da8b244 100644 --- a/extend/Ca/Ca.php +++ b/extend/Ca/Ca.php @@ -115,7 +115,7 @@ abstract class Ca */ public function addUserSignConfig(string $user_id, string $card_num, array $data): bool { - $option = [ + $arg = [ 'form_params' => [ 'userId' => $user_id,//用户标识信息(为云证书entityId) 'configKey' => $user_id, // 签章配置唯一标识,一张云证书配置一个 @@ -130,17 +130,41 @@ abstract class Ca ]; try { - $response = $this->httpRequest( - $this->api_url . '/signature-server/api/open/signature/userSignConfig', - $option - ); + $option = [ + "headers" => [ + "app_id" => $this->app_id, + "signature" => $this->getRequestSign($arg), + ], + ]; + + $option = array_merge($arg, $option); + + $response = $this->client->post($this->api_url . '/signature-server/api/open/signature/userSignConfig', $option); + + if ($response->getStatusCode() != '200') { + // 请求失败 + throw new BusinessException($response->getBody()->getContents()); + } + + $body = json_decode($response->getBody(), true); + if (empty($body)) { + // 返回值为空 + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } - dump($response); if ($response['result_code'] == "1104"){ // 用户标识已经存在,请检查! return true; } + if ($body['result_code'] != 0) { + // 请求失败 + if (!empty($body['result_msg'])) { + throw new BusinessException($body['result_msg']); + } + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + return true; } catch (GuzzleException $e) { throw new BusinessException($e->getMessage()); diff --git a/extend/Wechat/Wechat.php b/extend/Wechat/Wechat.php index e268528..d995513 100644 --- a/extend/Wechat/Wechat.php +++ b/extend/Wechat/Wechat.php @@ -342,4 +342,80 @@ class Wechat throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR); } } + + /** + * 生成UrlScheme + * @throws NotFoundExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ContainerExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function createUrlScheme(array $options): array|string + { + try { + $this->createApp($this->config['app_id'], $this->config['secret']); + + $client = $this->createClient($this->config['app_id'], $this->config['secret']); + + $response = $client->postJson('wxa/generatescheme', $options); + + if ($response->isFailed()) { + // 出错了,处理异常 + $result = $response->toArray(); + if(empty($result)){ + // 返回值为空 + throw new BusinessException("返回值为空"); + } + if (isset($result['errcode'])){ + throw new BusinessException($result['errmsg']); + } + throw new BusinessException(); + } + + return $response->toArray(); + } catch (\Exception $e) { + throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR); + } + } + + /** + * 获取UrlScheme + * @throws NotFoundExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ContainerExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function getUrlScheme(array $options): array|string + { + try { + $this->createApp($this->config['app_id'], $this->config['secret']); + + $client = $this->createClient($this->config['app_id'], $this->config['secret']); + + $response = $client->postJson('/wxa/queryscheme', $options); + + if ($response->isFailed()) { + // 出错了,处理异常 + $result = $response->toArray(); + if(empty($result)){ + // 返回值为空 + throw new BusinessException("返回值为空"); + } + if (isset($result['errcode'])){ + throw new BusinessException($result['errmsg']); + } + throw new BusinessException(); + } + + return $response->toArray(); + } catch (\Exception $e) { + throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR); + } + } } \ No newline at end of file