easywechat4.x升级到6.x
This commit is contained in:
@@ -4,7 +4,6 @@ namespace app\common\service;
|
||||
|
||||
use app\common\model\Accounts;
|
||||
use app\common\model\User;
|
||||
use EasyWeChat\Factory;
|
||||
use app\common\traits\ServiceTrait;
|
||||
|
||||
class UserService
|
||||
@@ -23,12 +22,10 @@ class UserService
|
||||
*/
|
||||
public static function wxLogin($code)
|
||||
{
|
||||
// 微信配置
|
||||
$wechatConfig = config('common.wechat');
|
||||
$app = Factory::miniProgram($wechatConfig);
|
||||
$result = $app->auth->session($code);
|
||||
if (isset($result['errcode'])) {
|
||||
throw new \Exception('微信登录失败:' . $result['errmsg']);
|
||||
// 微信登录(EasyWeChat 6.x: code2session)
|
||||
$result = (new EasyWeChatService())->login($code);
|
||||
if (empty($result['openid'])) {
|
||||
throw new \Exception('微信登录失败:' . ($result['errmsg'] ?? '未知错误'));
|
||||
}
|
||||
|
||||
$openid = $result['openid'];
|
||||
|
||||
Reference in New Issue
Block a user