-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
企业微信第三方服务商修复 #1307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
企业微信第三方服务商修复 #1307
Conversation
Chrisleung
commented
Jul 20, 2018
- 修复设置授权配置时,系统提示参数为空的问题
- 修复系统存在多个第三方应用时,各个应用的suite_ticket相互覆盖,导致请求失败的问题(suite_ticket按服务商ID-应用ID区分)
suite_ticket按服务商ID-应用ID区分
public function setSession(array $data) | ||
{ | ||
return $this->httpPostJson('cgi-bin/service/set_session_info', compact('data')); | ||
return $this->httpPostJson('cgi-bin/service/set_session_info', $data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成这样如何?
- return $this->httpPostJson('cgi-bin/service/set_session_info', compact('data'));
+ return $this->httpPostJson('cgi-bin/service/set_session_info', [
+ 'pre_auth_code' => $this->getPreAuthCode()['pre_auth_code'],
+ 'session_info' => $data,
+ ]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre_auth_code
后续还需要参与拼接授权url, 需要预先生成.
改成那样的话,后续获取不到 pre_auth_code
企业授权应用-从服务商网站发起
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
拼接授权 URL 中的 pre_auth_code
要和这里的 pre_auth_code
一样?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对的, pre_auth_code
相当于一个令牌,要先获取,
再用 setSession
去设置这次授权是 正式授权
还是 测试授权
最后返回 授权URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EasyWeChat\OpenWork\Corp\Client
内有个 getPreAuthorizationUrl
方法可以获取 授权URL
但是这个方法还差个 授权配置处理
即 setSession
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样?
public function setSession($preAuthCode, array $info)
{
//
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mingyoung 看看这样改行不行?
配置好 auth_type
后, 可以直接使用 getPreAuthorizationUrl
获取授权URL
public function getPreAuthorizationUrl(string $redirectUri = '', string $state = '')
{
$redirectUri || $redirectUri = $this->app->config['redirect_uri_install'];
$state || $state = rand();
+ $preAuthCode=$this->getPreAuthCode()['pre_auth_code'];
+ $this->setSession($preAuthCode, array("auth_type"=>$this->app->config['auth_type']));
$params = [
'suite_id' => $this->app['config']['suite_id'],
'redirect_uri' => $redirectUri,
- 'pre_auth_code' => $this->getPreAuthCode()['pre_auth_code'],
+ 'pre_auth_code' => $preAuthCode,
'state' => $state,
];
return 'https://open.work.weixin.qq.com/3rdapp/install?'.http_build_query($params);
}
...
- public function setSession(array $data)
+ public function setSession(string $preAuthCode, array $sessionInfo)
{
- return $this->httpPostJson('cgi-bin/service/set_session_info', $data);
+ return $this->httpPostJson('cgi-bin/service/set_session_info', array(
+ "pre_auth_code" => $preAuthCode,
+ "session_info" => $sessionInfo
+ ));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两个 API 还是分开吧,还有 auth_type
其实没必要写到配置?动态传入即可
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
两个 API分开调用的话, getPreAuthorizationUrl
得传入已设置授权配置的 pre_auth_code
才能正常使用.
setSession
的 sessionInfo
是必须, 但是的参数 appid
auth_type
不是必须,所以设置了一个默认值. 设置授权配置
- public function getPreAuthorizationUrl(string $redirectUri = '', string $state = '')
+ public function getPreAuthorizationUrl(string $preAuthCode, string $redirectUri = '', string $state = '')
{
$redirectUri || $redirectUri = $this->app->config['redirect_uri_install'];
$state || $state = rand();
$params = [
'suite_id' => $this->app['config']['suite_id'],
'redirect_uri' => $redirectUri,
- 'pre_auth_code' => $this->getPreAuthCode()['pre_auth_code'],
+ 'pre_auth_code' => $preAuthCode,
'state' => $state,
];
return 'https://open.work.weixin.qq.com/3rdapp/install?' . http_build_query($params);
}
...
- public function setSession(array $data)
+ public function setSession(string $preAuthCode, array $sessionInfo = array())
{
- return $this->httpPostJson('cgi-bin/service/set_session_info', compact('data'));
+ return $this->httpPostJson('cgi-bin/service/set_session_info', array(
+ "pre_auth_code" => $preAuthCode,
+ "session_info" => $sessionInfo
+ ));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Chrisleung 后面这个就对了。我当时看了他的文档,他这个设置授权信息根本就没有用处,正式授权和测试授权收到的数据没有什么差别。 当时我写的时候项目着急交,就忘记处理这里了。