Skip to content

Conversation

Chrisleung
Copy link

  • 修复设置授权配置时,系统提示参数为空的问题
  • 修复系统存在多个第三方应用时,各个应用的suite_ticket相互覆盖,导致请求失败的问题(suite_ticket按服务商ID-应用ID区分)

@overtrue
Copy link
Collaborator

@mingyoung

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);
Copy link
Collaborator

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,
+ ]);

Copy link
Author

@Chrisleung Chrisleung Jul 20, 2018

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
企业授权应用-从服务商网站发起

Copy link
Collaborator

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 一样?

Copy link
Author

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

Copy link
Author

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

Copy link
Collaborator

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)
{
    //
}

Copy link
Author

@Chrisleung Chrisleung Jul 21, 2018

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
+        ));
     }
 

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个 API 还是分开吧,还有 auth_type 其实没必要写到配置?动态传入即可

Copy link
Author

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 才能正常使用.
setSessionsessionInfo 是必须, 但是的参数 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
+        ));
    }

Copy link
Contributor

@keacefull keacefull Jul 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chrisleung 后面这个就对了。我当时看了他的文档,他这个设置授权信息根本就没有用处,正式授权和测试授权收到的数据没有什么差别。 当时我写的时候项目着急交,就忘记处理这里了。

@mingyoung
Copy link
Collaborator

#1309

@mingyoung mingyoung closed this Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants