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

125 lines
3.7 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
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 App\Models\Agent;
  5. use App\Service\OpenPlatform;
  6. use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client;
  7. use Illuminate\Support\Facades\Cache;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Redis;
  10. /**
  11. * 仅用于测试
  12. * Class TController
  13. * @package App\Http\Controllers\Api
  14. */
  15. class TestController
  16. {
  17. public function index()
  18. {
  19. $redis_key = 'mini_program_set_host:' . substr(md5(env('APP_URL')), 0, 10);
  20. Redis::del($redis_key);
  21. $redis_key = 'mini_program_set_privacy';
  22. Redis::del($redis_key);
  23. $agent = Agent::find(14);
  24. $openPlatform = new OpenPlatform();
  25. $refreshToken = $openPlatform->refreshToken($agent->appid);
  26. if (!$refreshToken) {
  27. dd('获取refresh_token失败');
  28. }
  29. $miniProgram = $openPlatform->miniProgram($agent->appid, $refreshToken);
  30. /** @var Client $code */
  31. $code = $miniProgram['code'] ?? null;
  32. if (!$code) {
  33. dd('获取code失败');
  34. }
  35. // dd($code->httpPostJson('cgi-bin/component/getprivacysetting'));
  36. $data = [
  37. 'privacy_ver' => 1, //1表示现网版本;2表示开发版。默认是2开发版
  38. 'owner_setting' => [
  39. 'contact_phone' => AdminSetting::val('service_component_phone'),
  40. 'notice_method' => '系统公告',
  41. ],
  42. 'setting_list' => [
  43. [
  44. "privacy_key" => "Location",
  45. "privacy_text" => "位置信息",
  46. "privacy_label" => "位置信息",
  47. ],
  48. [
  49. "privacy_key" => "PhoneNumber",
  50. "privacy_text" => "手机号",
  51. "privacy_label" => "手机号",
  52. ],
  53. [
  54. "privacy_key" => "UserInfo",
  55. "privacy_text" => "用户信息(微信昵称、头像)",
  56. "privacy_label" => "用户信息(微信昵称、头像)",
  57. ],
  58. ],
  59. ];
  60. dd($code->httpPostJson('cgi-bin/component/setprivacysetting', $data));
  61. }
  62. /**
  63. * 模拟登录
  64. * @param $user_id
  65. * @return string
  66. */
  67. private function login($user_id)
  68. {
  69. $token_key = md5($user_id . env('APP_KEY'));
  70. Cache::put($token_key, $user_id);
  71. return $token_key;
  72. }
  73. public function index2()
  74. {
  75. $handle = fopen(base_path('area.txt'), 'r');
  76. if ($handle) {
  77. DB::statement('TRUNCATE `areas`;');
  78. while (($line = fgets($handle, 4096)) !== false) {
  79. $line = trim($line);
  80. $last2 = substr($line, 4, 2); //区划码后2位
  81. $front2 = substr($line, 0, 2); //区划码前2位
  82. $front4 = substr($line, 0, 4); //区划码前4位
  83. //判断是否是直辖市,是直辖市则再插入一次上条记录作为二级联动
  84. if (isset($last4, $arr, $parent_arr[$front2]) && $last4 == '0000' && $last2 != '00') {
  85. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  86. $parent_arr[$front4] = $insert_id;
  87. //对直辖市不做省直辖县处理,如:重庆市
  88. $parent_arr[$front2] = $insert_id;
  89. }
  90. $last4 = substr($line, 2, 4); //区划码后4位
  91. $arr = preg_split('/\s+/', $line);
  92. if (count($arr) !== 2) continue;
  93. if ($last4 == '0000') {
  94. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => 0, 'name' => $arr[1]]);
  95. $parent_arr[$front2] = $insert_id;
  96. } else if ($last2 == '00') {
  97. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  98. $parent_arr[$front4] = $insert_id;
  99. } else {
  100. //考虑到省直辖县级市情况,如:海南琼海市、湖北仙桃市等,但重庆市的省辖县除外(已在上面判断直辖市逻辑中做处理)
  101. $parent_id = $parent_arr[$front4] ?? $parent_arr[$front2];
  102. DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_id, 'name' => $arr[1]]);
  103. }
  104. }
  105. } else {
  106. return 'open file fail!';
  107. }
  108. return 'success';
  109. }}