|
|
<?php
namespace App\Http\Controllers\Api;
use App\Models\AdminSetting;use App\Models\Agent;use App\Service\OpenPlatform;use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client;use Illuminate\Support\Facades\Cache;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Redis;
/** * 仅用于测试 * Class TController * @package App\Http\Controllers\Api */class TestController{ public function index() { $redis_key = 'mini_program_set_host:' . substr(md5(env('APP_URL')), 0, 10); Redis::del($redis_key);
$redis_key = 'mini_program_set_privacy'; Redis::del($redis_key);
$agent = Agent::find(14); $openPlatform = new OpenPlatform(); $refreshToken = $openPlatform->refreshToken($agent->appid); if (!$refreshToken) { dd('获取refresh_token失败'); } $miniProgram = $openPlatform->miniProgram($agent->appid, $refreshToken);
/** @var Client $code */ $code = $miniProgram['code'] ?? null; if (!$code) { dd('获取code失败'); }
// dd($code->httpPostJson('cgi-bin/component/getprivacysetting'));
$data = [ 'privacy_ver' => 2, //1表示现网版本;2表示开发版。默认是2开发版
'owner_setting' => [ 'contact_phone' => AdminSetting::val('service_component_phone'), 'notice_method' => '系统公告', ], 'setting_list' => [ [ "privacy_key" => "Location", "privacy_text" => "位置信息", "privacy_label" => "位置信息", ], [ "privacy_key" => "PhoneNumber", "privacy_text" => "手机号", "privacy_label" => "手机号", ], [ "privacy_key" => "UserInfo", "privacy_text" => "用户信息(微信昵称、头像)", "privacy_label" => "用户信息(微信昵称、头像)", ], ], ];
dd($code->httpPostJson('cgi-bin/component/setprivacysetting', $data));
}
/** * 模拟登录 * @param $user_id * @return string */ private function login($user_id) { $token_key = md5($user_id . env('APP_KEY')); Cache::put($token_key, $user_id); return $token_key; }
public function index2() { $handle = fopen(base_path('area.txt'), 'r'); if ($handle) { DB::statement('TRUNCATE `areas`;'); while (($line = fgets($handle, 4096)) !== false) { $line = trim($line);
$last2 = substr($line, 4, 2); //区划码后2位
$front2 = substr($line, 0, 2); //区划码前2位
$front4 = substr($line, 0, 4); //区划码前4位
//判断是否是直辖市,是直辖市则再插入一次上条记录作为二级联动
if (isset($last4, $arr, $parent_arr[$front2]) && $last4 == '0000' && $last2 != '00') { $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]); $parent_arr[$front4] = $insert_id; //对直辖市不做省直辖县处理,如:重庆市
$parent_arr[$front2] = $insert_id; }
$last4 = substr($line, 2, 4); //区划码后4位
$arr = preg_split('/\s+/', $line); if (count($arr) !== 2) continue; if ($last4 == '0000') { $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => 0, 'name' => $arr[1]]); $parent_arr[$front2] = $insert_id; } else if ($last2 == '00') { $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]); $parent_arr[$front4] = $insert_id; } else { //考虑到省直辖县级市情况,如:海南琼海市、湖北仙桃市等,但重庆市的省辖县除外(已在上面判断直辖市逻辑中做处理)
$parent_id = $parent_arr[$front4] ?? $parent_arr[$front2]; DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_id, 'name' => $arr[1]]); } } } else { return 'open file fail!'; } return 'success'; }}
|