海南旅游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.

92 lines
2.9 KiB

5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 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\Agent;
  4. use App\Service\OpenPlatform;
  5. use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client;
  6. use Illuminate\Support\Facades\Cache;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Redis;
  9. /**
  10. * 仅用于测试
  11. * Class TController
  12. * @package App\Http\Controllers\Api
  13. */
  14. class TestController
  15. {
  16. public function index()
  17. {
  18. $redis_key = 'mini_program_set_host:' . substr(md5(env('APP_URL')), 0, 10);
  19. Redis::del($redis_key);
  20. $agent = Agent::find(3);
  21. $openPlatform = new OpenPlatform();
  22. $refreshToken = $openPlatform->refreshToken($agent->appid);
  23. if (!$refreshToken) {
  24. dd('获取refresh_token失败');
  25. }
  26. $miniProgram = $openPlatform->miniProgram($agent->appid, $refreshToken);
  27. /** @var Client $code */
  28. $code = $miniProgram['code'] ?? null;
  29. if (!$code) {
  30. dd('获取code失败');
  31. }
  32. dd($code->httpPostJson('cgi-bin/component/getprivacysetting')); }
  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. }}