easywechat4.x升级到6.x

This commit is contained in:
Dev
2026-09-21 14:57:50 +08:00
parent 39882c6cf2
commit 5f4c8147ca
11 changed files with 263 additions and 185 deletions
@@ -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'];