Quick start of nailing third-party enterprise application development

Quick start of nailing third-party enterprise application development

Getting started with quick start

1. Create applet

1.1. Login developer background

Sign in Nail developer background , select application development - third party enterprise application - applet, and click create application.

1.2. Fill in basic information

Fill in the basic application information, including application name, application Logo, application type and application introduction.

1.3. View application information

After successful creation, you can view the created application in the application list. Click application to view the details of the application, as shown in the following figure:

2. Set the security domain name

The applet needs to set one or more server security domain names (or IP) in advance. The front end of the applet can only communicate with the server through these security domain names (or IP). When the security domain name is updated, the version needs to be repackaged and uploaded in the IDE before the set domain name will take effect.

In essence, the network communication between the front-end and back-end of the applet is the same as that of the front-end and back-end of the ordinary H5. Therefore, when you make a quick experience, you can fill in any domain name / IP address that can be accessed by the environment where the front end of the applet is located, such as the local address of your own office computer or the address in the LAN.

Is to add the domain name or address of your server

3. Set interface permissions

Nailing has opened a wealth of server interface capabilities, and developers can use these interface capabilities to realize the integration of enterprise system and nailing. Before calling the interface, you need to apply for and set the interface call permission, including address book permission, external contact permission, approval permission, internal purchase and development permission, etc. As shown in the figure below.

4. Development management (create callback)

Set the callback URL to activate the interface. No public domain name can be exposed by intranet penetration for nailing callback

5. Download source code

Use the command git clone to download the code, or directly download it from the code warehouse in the form of HTTP.

Server code
git clone https://github.com/opendingtalk/eapp-isv-quick-start-java.git

Front end code
git clone https://github.com/opendingtalk/eapp-isv-quick-start-fe.git

6. Setting and modifying source code

6.1. Server side

6.1.1. Configuration code

Modify com config. Constant. Configuration in Java class

 * Constant definition class in project
public class Constant {
     * The SuiteKey of the application, log in to the developer background, click application management, and enter the application. The details can be seen
    public static final String SUITE_KEY="Voucher and basic information page SuiteKey Value of";

     * The SuiteSecret of the application, log in to the developer background, click application management, and enter the application. The details can be seen
    public static final String SUITE_SECRET="Voucher and basic information page SuiteSecret Value of";

     * Callback URL signature. Sign the application Token, log in to the developer background, click application management, and enter the application. The details can be seen
    public static final String TOKEN = "Customization should be consistent with that in development management `Token` bring into correspondence with";

     * Callback URL encryption and decryption. The "data encryption key" of the application, log in to the developer background, click application management, and enter the application. The details can be seen
    public static final String ENCODING_AES_KEY = "Customization and development management `Data encryption key` bring into correspondence with";

     * Used to temporarily save the TICKET value sent by the nail
    public static String TICKET;

6.1.2. Business code

Modify com controller. CallbackController. dingCallback method in Java class

//Add the following code to else if (EVENT_SUITE_TICKET.equals(eventType)) {}
//Used to update Ticket
Constant.TICKET = String.valueOf(callBackContent.get("SuiteTicket"));

//Add the following code to else if (EVENT_TMP_AUTH_CODE.equals(eventType)) {}, which can also be extracted into method calls
//It is used to activate the application. It is called when you click to open the application in version management and publishing
try {
    //Do different business processing according to the callback data type
    String authCode = callBackContent.getString("AuthCode");
    String authCorpId = callBackContent.getString("AuthCorpId");

    //bizLogger.info("received approval task progress update:" + plainText);
    //Obtain third-party enterprise voucher suite_access_token
    DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/service/get_suite_token");
    OapiServiceGetSuiteTokenRequest request = new OapiServiceGetSuiteTokenRequest();

    OapiServiceGetSuiteTokenResponse response = client.execute(request);
    JSONObject jsonObject = JSONObject.parseObject(response.getBody());
    String suite_access_token = jsonObject.getString("suite_access_token");
    System.out.println("Get suite_access_token===" + suite_access_token);
    //Obtain permanent authorization code
    DingTalkClient client1 = new DefaultDingTalkClient("https://oapi.dingtalk.com/service/get_permanent_code?suite_access_token=" + suite_access_token);
    OapiServiceGetPermanentCodeRequest req = new OapiServiceGetPermanentCodeRequest();
    OapiServiceGetPermanentCodeResponse rsp = client1.execute(req);
    JSONObject jsonObject1 = JSONObject.parseObject(rsp.getBody());
    String permanent_code = jsonObject1.getString("permanent_code");
    System.out.println("Permanent authorization code obtained===" + permanent_code);
    //String permanent_code = jsonObject1.getString("permanent_code");
    //Activate application
    DingTalkClient client3 = new DefaultDingTalkClient("https://oapi.dingtalk.com/service/activate_suite?suite_access_token=" + suite_access_token);
    OapiServiceActivateSuiteRequest req3 = new OapiServiceActivateSuiteRequest();
    OapiServiceActivateSuiteResponse rsp3 = client3.execute(req3);
    System.out.println("Activate application results===" + rsp.getBody());
    //todo: realize the business logic of approval, such as sending messages
} catch (ApiException e) {

Modify com controller. IndexController. getSuiteTicket(String suiteKey) method in Java class

private String getSuiteTicket(String suiteKey) {
    //Returns the Ticket value pushed by the nail
    return Constant.TICKET;

6.2. front end

download Nailing applet developer tool IDE , install and open

After opening the IDE, select the eapp ISV quick start Fe folder of the front-end project you downloaded, and select the type of application you developed,

After opening, click login in the upper right corner to open the code scanning login interface, and use nail scanning to log in to the IDE.

Note: if the developer has opened the IDE, please close and reopen it. You can choose to open a new project only after opening it for the first time.

Select the project type, that is, the application type to be developed.

Click the login button in the upper right corner to login with nail scanning code.

6.2.1. Modify front end configuration

Modify the file eapp ISV quick start Fe / page / index / index js.

The IP PORT is the local IP and PORT. Note that the IP or domain name in the url must be the security domain name of the application set in the developer platform.

let domain = "https://sakura. XXXXXXXXXXX "; / / just set the address for intranet penetration

7. Add experience organization and open application

Important: enterprise oriented applications can only be experienced after being opened by enterprises. You need to create a special experience organization and open this application for this organization.

Please note: the experience organization added here is to create a new test organization, and cannot add an existing organization as an experience organization - such as the development organization where the application is located.

The test application can be opened directly. The formal application needs to verify the effectiveness of the callback and set the callback URL before it can be opened. This demo suggests creating a test application, so you can temporarily ignore the verification of callback effectiveness, and you can directly open this application.

Add a team that is not the current application holder, and then click open application. At this time, make sure your server is open

8. Project management nail remote

Then start the project. If the user information userid is obtained, it indicates that the application runs successfully.

Posted by quickphp on Mon, 23 May 2022 05:05:29 +0300