liumiao
2021-04-25 a3a1c0bae74bd8fce63eb13a8f621108fdb22361
commit | author | age
b37604 1 <?php
Z 2 /**
3  * Notes : 号码认证服务
4  * User : Joker_Wangx
5  */
6
7 namespace App\Common\Aliyun;
8
9 use AlibabaCloud\Client\AlibabaCloud;
10 use AlibabaCloud\Client\Exception\ClientException;
11 use AlibabaCloud\Client\Exception\ServerException;
12
13 class PnvsAction
14 {
15     public function __construct()
16     {
17         $config = config('aliyun.pnvs');
18         AlibabaCloud::accessKeyClient($config['accessKeyId'], $config['accessKeySecret'])
19             ->regionId('cn-hangzhou')
20             ->asDefaultClient();
21     }
22
23     /**
24      * 一键登录取号接口
25      * 文档地址 https://help.aliyun.com/document_detail/115500.html?spm=a2c4g.11186623.6.568.2aa050b9UJ3Nod
26      * @param $AccessToken
27      * @param string $OutId
28      * @return array|string
29      */
30     public function getMobile($AccessToken, $OutId = '123456')
31     {
32         try
33         {
34             $result = AlibabaCloud::rpc()
35                 ->product('Dypnsapi')
36                 ->scheme('https')// https | http
37                 ->version('2017-05-25')
38                 ->action('GetMobile')
39                 ->method('POST')
40                 ->host('dypnsapi.aliyuncs.com')
41                 ->options([
42                     'query' => [
43                         'RegionId' => "cn-hangzhou",
44                         'AccessToken' => $AccessToken,
45                         'OutId' => $OutId,
46                     ],
47                 ])
48                 ->request();
49             $result = $result->toArray();
50             if($result['Code'] != "OK")
51             {
52                 return $result['Message'] . "[" . $result['Code'] . "]";
53             }
54             else
55             {
56                 return $result;
57             }
58         }
59         catch (ClientException $e)
60         {
61             return $e->getErrorMessage();
62         }
63         catch (ServerException $e)
64         {
65             return $e->getErrorMessage() . PHP_EOL;
66         }
67     }
68 }