Skip to main content

Background Information

Contacts data (user names, user job titles, and department names) is important sensitive data of an organization. Requirements vary depending on the app deployment method used by the service provider. Some deployment methods require Contacts encryption; otherwise, the app cannot be listed on the App Market. To meet the requirement of “obtaining sensitive fields on the user side while preventing developers from accessing them,” DingTalk provides the secure rendering component (open-data) solution for a safer and better experience.

Procedure

  1. Concatenate the user sign-in state URL on the front-end page. Note The sign-in state URL is primarily constructed based on the callback URL (the ISV’s own front-end page link, such as the app Home URL or the URL of a page that uses the H5 rendering component). When the user redirects to the sign-in state URL on the client, they are ultimately redirected to the callback URL.
    1. Encode the callback URL. Note https://open.dingtalk.com/document is used as an example in all steps.
    2. Add the fixed prefix http://auth.dingtalk.com/login?redirectUri=.
    3. Encode the URL again.
    4. Add the fixed prefix https://login.dingtalk.com/oauth2/auth?response_type=code&client_id=dingwa4tibze6jwz7mgv&scope=openid&state=dddd&redirect_uri= and concatenate it to obtain the sign-in state URL.
    5. Import the open-data SDK on the front-end page.
      Note
      • Place the SDK script within the <head> tag and before all other <script> tags; otherwise, the SDK does not take effect.
      • The SDK content is returned dynamically. Import it strictly as shown in the demo. Do not save it locally in the project and then bundle it.
    6. Load the data from open-data on the front-end page.
      1. Call the DTOpenData.init method to initialize. Note This method returns a Boolean value indicating whether initialization succeeds or fails. If initialization fails, it is usually because Step 1 was performed incorrectly or the sign-in state has expired. In that case, reconstruct the “sign-in state URL” and redirect to it again.
      2. When there is data on the page that needs secure rendering, construct a dt-open-data element on the page and correctly set its open-type and open-id attributes. After the DOM element is set, call the DTOpenData.update method and pass in the DOM element objects to be rendered to complete rendering automatically. Note The number of DOM nodes passed into the DTOpenData.update method at one time cannot exceed 200; otherwise, rendering fails.

SDK Usage Example

(Optional) Content Translation

Message Notification Template Content Translation

When sending a notification message, you can include IDs in the content using template parameter syntax. DingTalk replaces them with user names or department names. The following Server API is involved:
  • Send Work Notifications
Add the enable_id_trans field to the original API parameters and set it to true to enable translation. This is required only for Third-party apps; Internal apps can ignore it. Contacts ID Translation Template Syntax
Here, DEPARTMENT_ID is a numeric department ID, and USER_ID is a user ID. For example:
  • departmentName=1departmentName=1 is replaced with the department name corresponding to department ID “1”, such as “DingTalk User Experience Department.”
  • userName=00001userName=00001 is replaced with the user name corresponding to userid “lisi007”, such as “John.”

Contacts Translation