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

111 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
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Models\AdminSetting;
  4. use App\Models\AgentProduct;
  5. use App\Models\MiniProgramUploadLog;
  6. use App\Service\OpenPlatform;
  7. use EasyWeChat\Factory;
  8. use Illuminate\Support\Facades\Cache;
  9. use Illuminate\Support\Facades\DB;
  10. /**
  11. * 仅用于测试
  12. * Class TController
  13. * @package App\Http\Controllers\Api
  14. */
  15. class TestController
  16. {
  17. public function index()
  18. {
  19. $appid = 'wx5bd5789ad8f89524';
  20. $message = json_decode('{"ToUserName":"gh_f4ab40774bed","FromUserName":"o4seR5d-TVCImgh2aE6UtrQn6LIM","CreateTime":"1631670431","MsgType":"event","Event":"weapp_audit_success","SuccTime":"1631670431"}', true);
  21. DB::table('mini_program_events')
  22. ->insert([
  23. 'type' => 1,
  24. 'response' => json_encode($message),
  25. 'event' => $message['MsgType'] ?? '',
  26. 'created_at' => now()
  27. ]);
  28. $openPlatform = new OpenPlatform();
  29. $refreshToken = $openPlatform->refreshToken($appid);
  30. //审核结果通知
  31. if (isset($message['MsgType'], $message['Event']) && $message['MsgType'] == 'event') {
  32. $auditArr = [
  33. 'weapp_audit_success' => 0, //成功
  34. 'weapp_audit_fail' => 1, //拒绝
  35. 'weapp_audit_delay' => 4, //审核延后
  36. ];
  37. //如果审核成功则发布
  38. if ($message['Event'] == 'weapp_audit_success') {
  39. $code = $openPlatform->code($appid, $refreshToken);
  40. $res = $code->release();
  41. dump($res);
  42. }
  43. $log = MiniProgramUploadLog::query()
  44. ->where('appid', $appid)
  45. ->orderBy('id', 'desc')
  46. ->first();
  47. $log->is_success = $auditArr[$message['Event']] ?? -1;
  48. $log->save();
  49. }
  50. }
  51. /**
  52. * 模拟登录
  53. * @param $user_id
  54. * @return string
  55. */
  56. private function login($user_id)
  57. {
  58. $token_key = md5($user_id . env('APP_KEY'));
  59. Cache::put($token_key, $user_id);
  60. return $token_key;
  61. }
  62. public function index2()
  63. {
  64. $handle = fopen(base_path('area.txt'), 'r');
  65. if ($handle) {
  66. DB::statement('TRUNCATE `areas`;');
  67. while (($line = fgets($handle, 4096)) !== false) {
  68. $line = trim($line);
  69. $last2 = substr($line, 4, 2); //区划码后2位
  70. $front2 = substr($line, 0, 2); //区划码前2位
  71. $front4 = substr($line, 0, 4); //区划码前4位
  72. //判断是否是直辖市,是直辖市则再插入一次上条记录作为二级联动
  73. if (isset($last4, $arr, $parent_arr[$front2]) && $last4 == '0000' && $last2 != '00') {
  74. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  75. $parent_arr[$front4] = $insert_id;
  76. //对直辖市不做省直辖县处理,如:重庆市
  77. $parent_arr[$front2] = $insert_id;
  78. }
  79. $last4 = substr($line, 2, 4); //区划码后4位
  80. $arr = preg_split('/\s+/', $line);
  81. if (count($arr) !== 2) continue;
  82. if ($last4 == '0000') {
  83. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => 0, 'name' => $arr[1]]);
  84. $parent_arr[$front2] = $insert_id;
  85. } else if ($last2 == '00') {
  86. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  87. $parent_arr[$front4] = $insert_id;
  88. } else {
  89. //考虑到省直辖县级市情况,如:海南琼海市、湖北仙桃市等,但重庆市的省辖县除外(已在上面判断直辖市逻辑中做处理)
  90. $parent_id = $parent_arr[$front4] ?? $parent_arr[$front2];
  91. DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_id, 'name' => $arr[1]]);
  92. }
  93. }
  94. } else {
  95. return 'open file fail!';
  96. }
  97. return 'success';
  98. }}