Gdian.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\service\mobile_get;
  3. use fast\Http;
  4. use stdClass;
  5. use think\Cache;
  6. class Gdian extends MobileGetService {
  7. const PUK_KEY = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCEMt8QR5miQjxNJQPh0ruKiq6KIaK9g7Rd3NPE7YfdHUgJwMQy760ddqesNmg2wNAzH2lezzFYjZp2RFxIHaeY2ZTvJnQAazfR8x9UiQ1u+Pz0RyouAhCzIFdLknRMdx/zwOPiYeI2KCZPNCVJFdTgpbo0prCwzi1qXMZEPWasewIDAQAB';
  8. const IV = '0123456789ABEDEF'; //IV参数必须是16位。
  9. protected $appid;
  10. protected $apppwd;
  11. protected $appCode='JS0020000091';
  12. protected $pubkey;
  13. protected $pubkey_getted;
  14. private $private_key;
  15. private $private_key_getted;
  16. protected $mode='debug';
  17. protected $api=[
  18. 'debug'=>[
  19. 'token'=>'http://223.160.16.24:8080/oauth',
  20. 'selectno'=>'http://223.160.16.24:8080/gwec-contact-web/openapi',
  21. 'area'=>'http://223.160.16.24:8080/gwec-contact-web/openapi',
  22. ],
  23. 'prod'=>[
  24. 'token'=>'https://partner.10099.com.cn/oauth',
  25. 'selectn0'=>'https://partner.10099.com.cn/openapi',
  26. 'area'=>'https://partner.10099.com.cn/openapi',
  27. ]
  28. ];
  29. public function __construct()
  30. {
  31. $this->appid='test103';
  32. $this->apppwd='123456';
  33. $this->pubkey=("-----BEGIN PUBLIC KEY-----
  34. MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCEMt8QR5miQjxNJQPh0ruKiq6K
  35. IaK9g7Rd3NPE7YfdHUgJwMQy760ddqesNmg2wNAzH2lezzFYjZp2RFxIHaeY2ZTv
  36. JnQAazfR8x9UiQ1u+Pz0RyouAhCzIFdLknRMdx/zwOPiYeI2KCZPNCVJFdTgpbo0
  37. prCwzi1qXMZEPWasewIDAQAB
  38. -----END PUBLIC KEY-----");
  39. $this->private_key = "-----BEGIN RSA PRIVATE KEY-----
  40. ......
  41. -----END RSA PRIVATE KEY-----";
  42. $this->pubkey_getted=openssl_pkey_get_public($this->pubkey);
  43. $this->private_key_getted=openssl_pkey_get_private($this->private_key);
  44. }
  45. public function fetchNo(){
  46. $areas=$this->getAreas();
  47. foreach ($areas as $area){
  48. foreach ($area['children'] as $city){
  49. $code=$city['areaCode'];
  50. $list=$this->request($this->url('selectno')."/fenxiao/openAcount/qryNumberNew?token={$this->token()}",[
  51. 'regionId'=>$code,
  52. 'currentPage'=>1,
  53. 'pageSize'=>30,
  54. ]);
  55. $noList=$list["result"]["numList"]??[];
  56. foreach ($noList as $noData){
  57. $result=$this->addMobile([
  58. 'no'=>$noData["accessNum"],
  59. 'city'=>$city['areaName'],
  60. ]);
  61. echo "{$city['areaName']}号码:{$noData['accessNum']},result:{$result}\n";
  62. self::log($logData=[
  63. 'no'=>$noData['accessNum'],
  64. 'result'=>$result?$result['id']:$result,
  65. ]);
  66. }
  67. }
  68. }
  69. }
  70. protected function request($url,$data=[]){
  71. $random='12345678';
  72. $randoms=$random.$random.$random;
  73. openssl_public_encrypt($randoms, $encrypted, $this->pubkey_getted);
  74. $code=base64_encode($encrypted);
  75. if(!$data){
  76. $data=new stdClass;
  77. }
  78. $newData=json_encode($data);
  79. $encrypt=openssl_encrypt($newData,'AES-192-CBC',$randoms,1,self::IV);
  80. $encrypted=base64_encode($encrypt);
  81. $requestData=[
  82. 'requestParams'=>$encrypted,
  83. ];
  84. //dd($newData);
  85. $headers=[
  86. 'ajaxrandomcode'=>$code,
  87. 'publicKey'=>self::PUK_KEY,
  88. 'CRC'=>$this->apppwd,
  89. 'ostype'=>'h5',
  90. 'appCode'=>$this->appCode,
  91. ];
  92. $arr=$this->post($url,$requestData,$headers);
  93. return $arr;
  94. }
  95. protected function token(){
  96. return Cache::remember('gidan_token',function (){
  97. $res=Http::get($this->url('token'),[
  98. 'username'=>$this->appid,
  99. 'password'=>$this->apppwd,
  100. 'sign'=>md5("{$this->appid}&{$this->apppwd}"),
  101. ]);
  102. $json=json_decode($res,true);
  103. if(empty($json['token'])){
  104. throw_user('get token fail '.$res);
  105. }
  106. return $json['token'];
  107. },29);
  108. }
  109. protected function url($api){
  110. $mode=$this->mode;
  111. return $this->api[$mode][$api];
  112. }
  113. public function getAreas(){
  114. $list=$this->request($this->url('area')."/fenxiao/openAcount/qryNumberOwnership?token={$this->token()}");
  115. //file_put_contents('aaa.json',json_encode($list,JSON_UNESCAPED_UNICODE));
  116. return $list['result']['regionalList']??[];
  117. }
  118. }