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.
99 lines
3.1 KiB
99 lines
3.1 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Models\AdminSetting;
|
|
use App\Models\AgentProduct;
|
|
use App\Models\MiniProgramUploadLog;
|
|
use EasyWeChat\Factory;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* 仅用于测试
|
|
* Class TController
|
|
* @package App\Http\Controllers\Api
|
|
*/
|
|
class TestController
|
|
{
|
|
public function index()
|
|
{
|
|
$appid = 'wx5bd5789ad8f89524';
|
|
$message = json_decode('{"ToUserName":"gh_f4ab40774bed","FromUserName":"o4seR5d-TVCImgh2aE6UtrQn6LIM","CreateTime":"1631670431","MsgType":"event","Event":"weapp_audit_success","SuccTime":"1631670431"}', true);
|
|
DB::table('mini_program_events')
|
|
->insert([
|
|
'type' => 1,
|
|
'response' => json_encode($message),
|
|
'event' => $message['MsgType'] ?? '',
|
|
'created_at' => now()
|
|
]);
|
|
|
|
//审核结果通知
|
|
if (isset($message['MsgType'], $message['Event']) && $message['MsgType'] == 'event') {
|
|
$auditArr = [
|
|
'weapp_audit_success' => 0, //成功
|
|
'weapp_audit_fail' => 1, //拒绝
|
|
'weapp_audit_delay' => 4, //审核延后
|
|
];
|
|
$log = MiniProgramUploadLog::query()
|
|
->where('appid', $appid)
|
|
->orderBy('id', 'desc')
|
|
->first();
|
|
$log->is_success = $auditArr[$message['Event']] ?? -1;
|
|
$log->save();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 模拟登录
|
|
* @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';
|
|
}}
|