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

120 lines
3.5 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
  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(2);
  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' => 2, //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. ];
  55. dd($code->httpPostJson('cgi-bin/component/setprivacysetting', $data));
  56. }
  57. /**
  58. * 模拟登录
  59. * @param $user_id
  60. * @return string
  61. */
  62. private function login($user_id)
  63. {
  64. $token_key = md5($user_id . env('APP_KEY'));
  65. Cache::put($token_key, $user_id);
  66. return $token_key;
  67. }
  68. public function index2()
  69. {
  70. $handle = fopen(base_path('area.txt'), 'r');
  71. if ($handle) {
  72. DB::statement('TRUNCATE `areas`;');
  73. while (($line = fgets($handle, 4096)) !== false) {
  74. $line = trim($line);
  75. $last2 = substr($line, 4, 2); //区划码后2位
  76. $front2 = substr($line, 0, 2); //区划码前2位
  77. $front4 = substr($line, 0, 4); //区划码前4位
  78. //判断是否是直辖市,是直辖市则再插入一次上条记录作为二级联动
  79. if (isset($last4, $arr, $parent_arr[$front2]) && $last4 == '0000' && $last2 != '00') {
  80. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  81. $parent_arr[$front4] = $insert_id;
  82. //对直辖市不做省直辖县处理,如:重庆市
  83. $parent_arr[$front2] = $insert_id;
  84. }
  85. $last4 = substr($line, 2, 4); //区划码后4位
  86. $arr = preg_split('/\s+/', $line);
  87. if (count($arr) !== 2) continue;
  88. if ($last4 == '0000') {
  89. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => 0, 'name' => $arr[1]]);
  90. $parent_arr[$front2] = $insert_id;
  91. } else if ($last2 == '00') {
  92. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  93. $parent_arr[$front4] = $insert_id;
  94. } else {
  95. //考虑到省直辖县级市情况,如:海南琼海市、湖北仙桃市等,但重庆市的省辖县除外(已在上面判断直辖市逻辑中做处理)
  96. $parent_id = $parent_arr[$front4] ?? $parent_arr[$front2];
  97. DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_id, 'name' => $arr[1]]);
  98. }
  99. }
  100. } else {
  101. return 'open file fail!';
  102. }
  103. return 'success';
  104. }}