You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.0 KiB
PHP
47 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\WeChat;
|
|
use Illuminate\Http\Request;
|
|
use Yo;
|
|
|
|
class WeChatController extends Controller
|
|
{
|
|
public function mp_login($we_chat, $code)
|
|
{
|
|
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid='
|
|
. $we_chat->app_id
|
|
. '&secret=' . $we_chat->app_secret
|
|
. '&js_code=' . $code . '&grant_type=authorization_code';
|
|
$info = file_get_contents($url);
|
|
$json = json_decode($info);
|
|
return get_object_vars($json);
|
|
}
|
|
|
|
public function login($code, $app_id)
|
|
{
|
|
$we_chat = WeChat::where('app_id', $app_id)->first();
|
|
$login = false;
|
|
if (!$we_chat) return false;
|
|
switch ($we_chat->type) {
|
|
case 1:
|
|
|
|
break;
|
|
case 2:
|
|
$login = $this->mp_login($we_chat, $code);
|
|
break;
|
|
}
|
|
return $login;
|
|
}
|
|
|
|
public function login_test(Request $request)
|
|
{
|
|
$code = $request->post('code');
|
|
$app_id = $request->post('app_id');
|
|
return Yo::echo([
|
|
'info' => $this->login($code, $app_id)
|
|
]);
|
|
}
|
|
}
|