Home WeChat Applet Mini Program Development Process analysis of developing enterprise WeChat applet

Process analysis of developing enterprise WeChat applet

Dec 23, 2020 am 09:22 AM
Enterprise WeChat Applets process

Process analysis of developing enterprise WeChat applet

Introduction:

Develop a small program that can only be accessed in Enterprise WeChat, and only authorized users in Enterprise WeChat can use it.

(Learning video sharing: Programming video)

Problem analysis:

First of all, there are several problems that need to be solved:

1. Only used in corporate WeChat and cannot be used in ordinary mini programs

Judge the current operating environment

2. Only authorized users can use this mini program

Permissions Verification

1: Ordinary WeChat, use account and password to log in, only for review, account permissions can be restricted

2: Enterprise WeChat, verify company ID, verify user ID, only those with permissions Allow use

3. Control search

Set "Not allowed to be searched" in the mini program management background

4. Control sharing

Close in the mini program Share

OK, after achieving the above points, only authorized users in Enterprise WeChat can see the mini program on the Workbench of Enterprise WeChat.

Processing Process

Okay, now that the problem has been clarified, let’s get started.

1. Develop the basic functions of the mini program and submit it for review

Yes, you read that right, submit it for review first, because only mini programs that pass the review can be bound to Enterprise WeChat. Therefore, first make the basic functions of the mini program, and you can limit some functions. In short, let this mini program be put on the shelves first. At the same time, set "not allowed to be searched" in the mini program's management background to avoid unnecessary trouble.

2. Associate the Mini Program with Enterprise WeChat

Enter the Enterprise WeChat backend-> Application Management-> Mini Program-> Associate the Mini Program, and then use the WeChat QR code of the Mini Program administrator to scan the code , just follow the instructions.

3. Get the Secret of the associated applet and set the visible range

The applet you just associated will appear on the applet page in the previous step. Click to enter, and then you will see the secret and visible range.

This secret is equivalent to the token used by the applet to access the company's WeChat data. Please keep it properly.

The visibility range is authorization. Which users can see this mini program. Those who are set to be visible will see the mini program on their corporate WeChat workbench.

4. Modify the mini program

Okay, it’s time for the main event.

4.1. Determine the operating environment

The mini program needs to determine the current operating environment (normal WeChat or enterprise WeChat) and whether the user using the current mini program has permission to use it.

var isWxWork = false;
wx.getSystemInfo({
  success(res) {
    console.log(res.environment);

    isWxWork = res.environment == 'wxwork';
    if (!isWxWork) {
        // 当前环境不是企业微信,怎么处理你随便
        return;
    }
    
    // 当前环境是企业微信,执行登陆,获取用户 code,用于后面的权限校验
    wx.qy.login({
      success: function (res) {
        if (res.code) {
            console.log(res.code);
            
            // 这里可以将 res.code 通过请求发送给后台,让后台做权限校验
        } else {
            console.log('登录失败!' + res.errMsg);
        }
      }
    });
  }
})
Copy after login

4.2. Permission verification

The background needs to call the following interfaces to perform permission verification.

1. Obtain access_token

https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=xxxx&corpsecret=xxxx

请求方式:GET
Copy after login

This interface is similar to the method of obtaining token in ordinary WeChat.

Among them, corpid is in the enterprise WeChat management background->My Company->Corporate Information->Corporate ID; corpsecret is the secret obtained after we associated the mini program in the previous step.

The returned content is as follows:

{
    "errcode": 0,
    "errmsg": "ok",
    "access_token": "xxxxxx",
    "expires_in": 7200
}
Copy after login

2. Get userid

https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session?access_token=xxx&js_code=xxx&grant_type=authorization_code

请求方式:GET
Copy after login

Among them, access_token is obtained by gettoken in the previous step; js_code is obtained when judging the running environment. res.code; grant_type fixed transmission authorization_code

The returned content is as follows:

{
    "userid": "bottle",
    "session_key": "xxxxx",
    "corpid": "xxxxxx",
    "deviceid": "xxxxxx",
    "errcode": 0,
    "errmsg": "ok"
}
Copy after login

The corpid here can be used to initially verify whether the current user has permissions, because no matter which company the person is from, as long as he uses Enterprise WeChat, using this applet, will return such a result. You need to verify whether the corpid is the ID of the company you authorize. If not, just return no permission without proceeding to the next step.

Of course corpid can also be used to handle situations where a small program is associated with multiple companies, but this is another issue. Let me briefly mention here, because it is a small program developed for other companies, our small program is also associated with two companies, one is our company and the other is the other company. This also facilitates our testing and only requires our own testers. Authorization allows them to use the exact same environment for testing.

3. Obtain user information (determine permissions)

https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=xxx&userid=xxx

请求方式:GET
Copy after login

Among them, access_token is the one we obtained by gettoken in the previous step; userid is the userid we obtained in the previous step.

The returned content is as follows:

With permission

{
    "errcode": 0,
    "errmsg": "ok",
    "userid": "xxx",
    "name": "xxx",
    "department": [],
    "position": "",
    "mobile": "xxx",
    "gender": "2",
    "email": "",
    "avatar": "http://p.qlogo.cn/bizmail/xxx/0",
    "status": 1,
    "isleader": 0,
    "extattr": {
        "attrs": []
    },
    "telephone": "",
    "enable": 1,
    "hide_mobile": 0,
    "order": [],
    "qr_code": "https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=xxx",
    "alias": "",
    "is_leader_in_dept": []
}
Copy after login

Without permission:

{
    "errcode": 60011,
    "errmsg": "no privilege to access/modify contact/party/agent , hint: [1564556097_7_8d45297bd21be3702ff430560e1f0652], from ip: 118.113.1.217, more info at https://open.work.weixin.qq.com/devtool/query?e=60011",
    "department": [],
    "order": [],
    "is_leader_in_dept": []
}
Copy after login

OK, the execution will be different depending on whether you have permission or not. The operation is enough, and I won’t go into details here.

Reference materials

Enterprise WeChat API (mini program): https://work.weixin.qq.com/api/doc#90000/90136/90289

Enterprise WeChat interface debugging tool: https://work.weixin.qq.com/api/devtools/devtool.php

Error code query tool: https://open.work.weixin.qq.com/devtool /query

Related recommendations: 小program development

The above is the detailed content of Process analysis of developing enterprise WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1672
14
PHP Tutorial
1277
29
C# Tutorial
1257
24
How to share screen on WeChat Enterprise How to share screen on WeChat Enterprise Feb 28, 2024 pm 12:43 PM

More and more enterprises choose to use exclusive enterprise WeChat, which not only facilitates communication between enterprises and customers and partners, but also greatly improves work efficiency. Enterprise WeChat has rich functions, among which the screen sharing function is very popular. During the meeting, by sharing the screen, participants can display content more intuitively and collaborate more efficiently. So how to share your screen efficiently in WeChat Enterprise? For users who don’t know yet, this tutorial guide will give you a detailed introduction. I hope it can help you! How to share screen on WeChat Enterprise? 1. In the blue area on the left side of the main interface of Enterprise WeChat, you can see a list of functions. We find the "Conference" icon. After clicking to enter, three conference modes will appear.

The difference between corporate WeChat and personal WeChat The difference between corporate WeChat and personal WeChat Jan 22, 2024 pm 01:25 PM

The differences between corporate WeChat and personal WeChat: 1. Service objects; 2. Functional differences; 3. Usage scenarios; 4. Group chat function; 5. Moments function; 6. Friend permissions; 7. Asset ownership; 8. Account ban differences ; 9. Marketing tool; 10. Security. Detailed introduction: 1. Service objects. Personal WeChat mainly serves the masses. It is a social tool that the public can use to communicate, share and interact. Enterprise WeChat is mainly aimed at corporate managers and internal employees, providing more efficient services. , Convenient office services; 2. Functional differences, personal WeChat, etc.

How to log in to corporate WeChat email How to log in to corporate WeChat email Mar 10, 2024 pm 12:43 PM

How to log in to the email address of Enterprise WeChat? You can log in to the email address in the Enterprise WeChat APP, but most users don’t know how to log in to the email address. Next is the graphic tutorial on how to log in to the email address of Enterprise WeChat brought by the editor for interested users. Come and take a look! Enterprise WeChat usage tutorial How to log in to the Enterprise WeChat email 1. First open the Enterprise WeChat APP, go to the [Workbench] at the bottom of the main page and click to come to the special area; 2. Then in the workbench area, select the [Enterprise Mailbox] service; 3. Then jump to the corporate email function page, click [Bind] or [Change Email] at the bottom; 4. Finally, enter [QQ Account] and [Password] on the page shown below to log in to the email.

How to set up automatic check-in on corporate WeChat How to set up automatic check-in on corporate WeChat Feb 23, 2024 pm 02:40 PM

How to set up automatic check-in on Enterprise WeChat? You can set up the automatic check-in function in Enterprise WeChat, but most friends don’t know how to set up automatic check-in on Enterprise WeChat. Next is the picture and text of how to set up automatic check-in on Enterprise WeChat brought by the editor. Tutorial, interested players come and take a look! WeChat usage tutorial: How to set up automatic punch-in in Enterprise WeChat 1. First open the Enterprise WeChat APP, enter the workbench interface and select the [Punch-in] function; 2. Then in the clock-in interface, select [Punch-in Settings] in [Leave Attendance Application]; 3 . Finally, on the function page of clock-in settings, slide the button behind [Quick clock-in to and from get off work] to automatically clock in.

How to use Enterprise WeChat - Tutorial on using Enterprise WeChat How to use Enterprise WeChat - Tutorial on using Enterprise WeChat Mar 04, 2024 pm 02:28 PM

Many friends don’t know how to use Enterprise WeChat, so the editor below will share the tutorial for using Enterprise WeChat. Let’s take a look. I believe it will be helpful to everyone. Step 1: Click the "Enterprise WeChat" icon to enter Enterprise WeChat. In the message section, we can join the group chat to chat with colleagues (as shown in the picture). Step 2: On the main interface of Enterprise WeChat, click "Contact Book" (as shown in the picture). Step 3: Enter the address book section, where we can view our contacts (as shown in the picture). Step 4: On the main interface of Enterprise WeChat, click "Workbench" (as shown in the picture). Step 5: Enter the workbench section, where we can carry out the company's daily small work (as shown in the picture). Step 6: On the main interface of Enterprise WeChat, click "Me" (as shown in the picture

Implement card flipping effects in WeChat mini programs Implement card flipping effects in WeChat mini programs Nov 21, 2023 am 10:55 AM

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l

How to open multiple Toutiao accounts? What is the process for applying for a Toutiao account? How to open multiple Toutiao accounts? What is the process for applying for a Toutiao account? Mar 22, 2024 am 11:00 AM

With the popularity of mobile Internet, Toutiao has become one of the most popular news information platforms in my country. Many users hope to have multiple accounts on the Toutiao platform to meet different needs. So, how to open multiple Toutiao accounts? This article will introduce in detail the method and application process of opening multiple Toutiao accounts. 1. How to open multiple Toutiao accounts? The method of opening multiple Toutiao accounts is as follows: On the Toutiao platform, users can register accounts through different mobile phone numbers. Each mobile phone number can only register one Toutiao account, which means that users can use multiple mobile phone numbers to register multiple accounts. 2. Email registration: Use different email addresses to register a Toutiao account. Similar to mobile phone number registration, each email address can also register a Toutiao account. 3. Log in with third-party account

How to apply for enterprise WeChat registration process How to apply for enterprise WeChat registration process Mar 25, 2024 am 10:54 AM

1. First, go to the homepage of the official WeChat Enterprise website and click [Register Now] to enter the Enterprise WeChat registration page. 2. Fill in the basic information of the company, including company name, administrator name, administrator mobile phone number, etc. 3. Select the administrator identity verification method. After verifying the administrator's identity, you can create a corporate WeChat account. 4. Then set the administrator account and password of Enterprise WeChat and choose how to use Enterprise WeChat. 5. After creating an Enterprise WeChat account, users need to download and install the Enterprise WeChat client before they can officially use the various functions of Enterprise WeChat.

See all articles