没有不值得去解决的问题,也没有不值得去学习的技术!

Implementing WeChat Login in ShopNC: Using Detector to Detect Browser-Related Flows

Under the mobile client, the web page directly redirects to the authorization page

1. When implementing WeChat login in the WeChat client, the QR code scanning layer that pops up should be canceled, and it should directly redirect to the authorization page, as shown in Figure 1:

Implementing WeChat login in the WeChat client, popping up the QR code scanning layer
Implementing WeChat login in the WeChat client, popping up the QR code scanning layer

2. In a mobile browser, the QR code scanning layer pops up, and an error occurs after scanning, as shown in Figure 2:

In a mobile browser, popping up the QR code scanning layer, error after scanning
In a mobile browser, popping up the QR code scanning layer, error after scanning

3. Admin – Platform – Member – Account Sync – WeChat Official Account Platform, as shown in Figure 3:
Execute SQL:
INSERT INTO `trade_setting`(`name`, `value`) VALUES (‘mp_weixin_isuse’,’1′)
INSERT INTO `trade_setting`(`name`, `value`) VALUES (‘mp_weixin_appid’,’wx5c318e640e87f7e8′)
INSERT INTO `trade_setting`(`name`, `value`) VALUES (‘mp_weixin_secret’,’1f436a3aa0dbfdac1c8e1c8f72d2fbec’)

Admin - Platform - Member - Account Sync - WeChat Official Account Platform
Admin – Platform – Member – Account Sync – WeChat Official Account Platform

4. Use Detector to detect the browser. Website: http://detector.dmolsen.com/ . It can automatically adapt to new browsers, versions, and devices by using a unique user agent string for each browser, and is built based on Modernizr, as shown in Figure 4:

Use Detector to detect the browser. Website: http://detector.dmolsen.com/
Use Detector to detect the browser. Website: http://detector.dmolsen.com/

5. Copy the directory lib/Detector to core/framework/Detector, as shown in Figure 5:

And set the directories: user-agents/core/, user-agents/extended/, config as writable;

Copy the directory lib/Detector to core/framework/Detector
Copy the directory lib/Detector to core/framework/Detector

6. The rules are formulated as follows. The code in the controller and template files is shown in Figures 6 and 7:

(1) PC, tablet: Pop up the QR code scanning layer (WeChat Open Platform, website application here);

(2) Mobile browser: Hidden;

(3) Mobile client: Directly redirect to the authorization page (WeChat Official Account Platform, service account here);

36kr.com: WeChat login is temporarily not supported on the mobile side, please log in using your bound phone number or email.
dianping.com: Hide the WeChat login button (this solution is adopted);

Code in the controller file
Code in the controller file
Code in the template file
Code in the template file

7. Under the mobile client, the code to directly redirect to the authorization page is shown in Figure 8:

Under the mobile client, the code to directly redirect to the authorization page
Under the mobile client, the code to directly redirect to the authorization page

8. Under the mobile client, the web page directly redirects to the authorization page, as shown in Figure 9:

Under the mobile client, the web page directly redirects to the authorization page
Under the mobile client, the web page directly redirects to the authorization page

9. An error occurred when committing to SVN, as shown in Figure 10:

the working copy at

is too old(format 10) to work with client version ‘1.8.10(r1615264)’ (expects format 31).you need upgrade the working copy first.

the working copy at is too old(format 10) to work with client version '1.8.10(r1615264)' (expects format 31)
the working copy at is too old(format 10) to work with client version ‘1.8.10(r1615264)’ (expects format 31)

10. Delete all .svn directories under core/framework/Detector to prevent SVN conflicts. The commit was successful, as shown in Figures 11 and 12:

Delete all .svn directories under core/framework/Detector to prevent SVN conflicts
Delete all .svn directories under core/framework/Detector to prevent SVN conflicts
SVN commit successful
SVN commit successful

11. Under the Edge browser, an error occurs, as shown in Figure 13:

SCRIPT16389: Unspecified error.

Under the Edge browser, error: SCRIPT16389: Unspecified error.
Under the Edge browser, error: SCRIPT16389: Unspecified error.

12. Open the URL: http://detector.dmolsen.com/ , and I found this error occurs there as well, as shown in Figure 14:

Open the URL: http://detector.dmolsen.com/ , and found this error occurs there as well
Open the URL: http://detector.dmolsen.com/ , and found this error occurs there as well

13. The solution is to base it on $_SERVER[‘HTTP_USER_AGENT’]. If it is IE10, IE11, or Edge, do not use Detector to detect the browser, as shown in Figure 15:

Based on $_SERVER['HTTP_USER_AGENT'], if it is IE10, IE11, or Edge, do not use Detector to detect the browser
Based on $_SERVER[‘HTTP_USER_AGENT’], if it is IE10, IE11, or Edge, do not use Detector to detect the browser

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系