海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Models\AdminSetting;
  4. use EasyWeChat\Factory;
  5. use Illuminate\Support\Facades\Cache;
  6. use Illuminate\Support\Facades\DB;
  7. /**
  8. * 仅用于测试
  9. * Class TController
  10. * @package App\Http\Controllers\Api
  11. */
  12. class TestController
  13. {
  14. public function index()
  15. {
  16. $appid = 'wx5bd5789ad8f89524';
  17. $setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
  18. $config = [
  19. 'app_id' => $setting['service_appid'],
  20. 'secret' => $setting['service_appsecret'],
  21. 'token' => $setting['service_token'],
  22. 'aes_key' => $setting['service_aeskey'],
  23. ];
  24. $app = Factory::openPlatform($config);
  25. $refreshToken = $app->getAuthorizer($appid)['authorization_info']['authorizer_refresh_token'] ?? null;
  26. if (!$refreshToken) {
  27. return $this->error('获取refresh_token失败');
  28. }
  29. $miniProgram = $app->miniProgram($appid, $refreshToken);
  30. $domain = $miniProgram['domain'];
  31. return $domain->setWebviewDomain([env('APP_URL')]);
  32. }
  33. /**
  34. * 模拟登录
  35. * @param $user_id
  36. * @return string
  37. */
  38. private function login($user_id)
  39. {
  40. $token_key = md5($user_id . env('APP_KEY'));
  41. Cache::put($token_key, $user_id);
  42. return $token_key;
  43. }
  44. public function index2()
  45. {
  46. $handle = fopen(base_path('area.txt'), 'r');
  47. if ($handle) {
  48. DB::statement('TRUNCATE `areas`;');
  49. while (($line = fgets($handle, 4096)) !== false) {
  50. $line = trim($line);
  51. $last2 = substr($line, 4, 2); //区划码后2位
  52. $front2 = substr($line, 0, 2); //区划码前2位
  53. $front4 = substr($line, 0, 4); //区划码前4位
  54. //判断是否是直辖市,是直辖市则再插入一次上条记录作为二级联动
  55. if (isset($last4, $arr, $parent_arr[$front2]) && $last4 == '0000' && $last2 != '00') {
  56. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  57. $parent_arr[$front4] = $insert_id;
  58. //对直辖市不做省直辖县处理,如:重庆市
  59. $parent_arr[$front2] = $insert_id;
  60. }
  61. $last4 = substr($line, 2, 4); //区划码后4位
  62. $arr = preg_split('/\s+/', $line);
  63. if (count($arr) !== 2) continue;
  64. if ($last4 == '0000') {
  65. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => 0, 'name' => $arr[1]]);
  66. $parent_arr[$front2] = $insert_id;
  67. } else if ($last2 == '00') {
  68. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  69. $parent_arr[$front4] = $insert_id;
  70. } else {
  71. //考虑到省直辖县级市情况,如:海南琼海市、湖北仙桃市等,但重庆市的省辖县除外(已在上面判断直辖市逻辑中做处理)
  72. $parent_id = $parent_arr[$front4] ?? $parent_arr[$front2];
  73. DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_id, 'name' => $arr[1]]);
  74. }
  75. }
  76. } else {
  77. return 'open file fail!';
  78. }
  79. return 'success';
  80. }}