Skip to content

Commit 89474f8

Browse files
committed
增加兼容开放平台的 web app等登录方式
1 parent 8cfe89f commit 89474f8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Wechat.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace xutl\wechat;
99

10-
1110
use Yii;
1211
use yii\base\Component;
1312
use yii\base\InvalidConfigException;

src/oauth/OAuth.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class OAuth extends OAuth2
3434
*/
3535
public $apiBaseUrl = 'https://api.weixin.qq.com';
3636

37+
/**
38+
* @var bool 是否使用openid
39+
*/
40+
public $useOpenId = true;
41+
3742
/**
3843
* 初始化组件
3944
*/
@@ -47,6 +52,24 @@ public function init()
4752
}
4853
}
4954

55+
/**
56+
* @inheritdoc
57+
*/
58+
protected function defaultNormalizeUserAttributeMap()
59+
{
60+
if ($this->useOpenId) {
61+
return [
62+
'id' => 'openid',
63+
'username' => 'nickname',
64+
];
65+
} else {
66+
return [
67+
'id' => 'unionid',
68+
'username' => 'nickname',
69+
];
70+
}
71+
}
72+
5073
/**
5174
* Composes user authorization URL.
5275
* @param array $params additional auth GET params.

0 commit comments

Comments
 (0)