การแก้ไข

หน้านี้อธิบายวิธีจัดการปัญหาเกี่ยวกับการตัดสินความสมบูรณ์

เมื่อมีการขอโทเค็นความสมบูรณ์ คุณจะมีตัวเลือกในการแสดงโทเค็น เล่นกล่องโต้ตอบของผู้ใช้ คุณอาจแสดงกล่องโต้ตอบเมื่อมี ด้วยการตัดสินความสมบูรณ์ กล่องโต้ตอบจะแสดงที่ด้านบนของแอป และแจ้งให้ผู้ใช้แก้ไขสาเหตุของปัญหา เมื่อปิดกล่องโต้ตอบแล้ว คุณสามารถยืนยันว่าปัญหาได้รับการแก้ไขแล้วด้วยคำขออื่นที่ส่งไปยังทีม Integrity API

กล่องโต้ตอบความสมบูรณ์

GET_LICENSED (ประเภทรหัส 1)

ปัญหาคำตัดสิน

เมื่อ appLicensingVerdict == "UNLICENSED" ซึ่งหมายความว่าบัญชีผู้ใช้ ไม่มีใบอนุญาต กล่าวคือ ผู้ใช้ไม่ได้ติดตั้งหรือซื้อแอปจาก Google Play

การแก้ไข

คุณสามารถแสดงกล่องโต้ตอบ GET_LICENSED เพื่อแจ้งให้ผู้ใช้ดาวน์โหลดแอปของคุณ Google Play หากผู้ใช้ยอมรับ บัญชีผู้ใช้จะได้รับอนุญาต (appLicensingVerdict == "LICENSED"). มีการเพิ่มแอปลงใน คลัง Play และ Google Play สามารถนำส่งอัปเดตแอปในนามของคุณได้

ตัวอย่าง UX

กล่องโต้ตอบ Play GET_LICENSED

CLOSE_UNKNOWN_ACCESS_RISK (ประเภทรหัส 2)

ปัญหาคำตัดสิน

เมื่อ environmentDetails.appAccessRiskVerdict.appsDetected มี "UNKNOWN_CAPTURING" หรือ "UNKNOWN_CONTROLLING" หมายความว่าไม่ทราบ แอปที่ทำงานอยู่ในอุปกรณ์ที่สามารถจับภาพหน้าจอ หรือ กำลังควบคุมอุปกรณ์

การแก้ไข

คุณสามารถแสดงกล่องโต้ตอบ CLOSE_UNKNOWN_ACCESS_RISK เพื่อแจ้งให้ผู้ใช้ปิดได้ แอปที่ไม่รู้จักทั้งหมดซึ่งอาจกำลังจับภาพหน้าจอหรือควบคุมอุปกรณ์ หากผู้ใช้แตะปุ่ม Close all แอปดังกล่าวทั้งหมดจะปิดไป

ตัวอย่าง UX

กล่องโต้ตอบสำหรับการปิดความเสี่ยงในการเข้าถึงที่ไม่รู้จัก

CLOSE_ALL_ACCESS_RISK (ประเภทรหัส 3)

ปัญหาคำตัดสิน

เมื่อ environmentDetails.appAccessRiskVerdict.appsDetected มีรายการใดก็ได้ต่อไปนี้ "KNOWN_CAPTURING", "KNOWN_CONTROLLING","UNKNOWN_CAPTURING" หรือ "UNKNOWN_CONTROLLING" หมายความว่ามีแอปที่ทำงานอยู่ในอุปกรณ์ที่ อาจกำลังจับภาพหน้าจอหรือควบคุมอุปกรณ์อยู่

การแก้ไข

คุณสามารถแสดงกล่องโต้ตอบ CLOSE_ALL_ACCESS_RISK เพื่อแจ้งให้ผู้ใช้ปิดทั้งหมด แอปที่สามารถจับภาพหน้าจอหรือควบคุมอุปกรณ์ได้ หากผู้ใช้แตะปุ่ม Close all แอปทั้งหมดจะปิดไปใน อุปกรณ์

ตัวอย่าง UX

กล่องโต้ตอบสำหรับการปิดความเสี่ยงในการเข้าถึงทั้งหมด

กล่องโต้ตอบขอความสมบูรณ์

เมื่อไคลเอ็นต์ขอโทเค็นความสมบูรณ์ คุณสามารถใช้วิธีการที่มีให้ใน StandardIntegrityToken (API มาตรฐาน) และ IntegrityTokenResponse (API คลาสสิก) showDialog(Activity activity, int integrityDialogTypeCode)

ขั้นตอนต่อไปนี้จะสรุปวิธีการใช้ Play Integrity API เพื่อแสดง กล่องโต้ตอบ GET_LICENSED:

  1. ขอโทเค็นความสมบูรณ์จากแอปของคุณ แล้วส่งโทเค็นไปยังเซิร์ฟเวอร์ของคุณ คุณสามารถใช้คำขอแบบมาตรฐานหรือคลาสสิกก็ได้

    Kotlin

    
    // Request an integrity token
    val tokenResponse: StandardIntegrityToken = requestIntegrityToken()
    // Send token to app server and get response on what to do next
    val yourServerResponse: YourServerResponse = sendToServer(tokenResponse.token())
    
    

    Java

    
    // Request an integrity token
    StandardIntegrityToken tokenResponse = requestIntegrityToken();
    // Send token to app server and get response on what to do next
    YourServerResponse yourServerResponse = sendToServer(tokenResponse.token());
    
    
  2. ในเซิร์ฟเวอร์ของคุณ ให้ถอดรหัสโทเค็นความสมบูรณ์และตรวจสอบ appLicensingVerdict ซึ่งอาจมีลักษณะดังนี้

    // Licensing issue
    {
      ...
      accountDetails: {
        appLicensingVerdict: "UNLICENSED"
      }
    }
    
  3. หากโทเค็นมี appLicensingVerdict: "UNLICENSED" ให้ตอบกลับแอปของคุณ เพื่อขอให้แสดงกล่องโต้ตอบการให้สัญญาอนุญาต

    Kotlin

    
    private fun getDialogTypeCode(integrityToken: String): Int{
    // Get licensing verdict from decrypted and verified integritytoken
    val licensingVerdict: String = getLicensingVerdictFromDecryptedToken(integrityToken)
    
    return if (licensingVerdict == "UNLICENSED") {
           1 // GET_LICENSED
       } else 0
    }
    
    

    Java

    
    private int getDialogTypeCode(String integrityToken) {
      // Get licensing verdict from decrypted and verified integrityToken
      String licensingVerdict = getLicensingVerdictFromDecryptedToken(integrityToken);
    
      if (licensingVerdict.equals("UNLICENSED")) {
        return 1; // GET_LICENSED
      }
      return 0;
    }
    
    
  4. ในแอป ให้โทรหา showDialog พร้อมรับรหัสที่ขอจาก เซิร์ฟเวอร์:

    Kotlin

    
    // Show dialog as indicated by the server
    val showDialogType: Int? = yourServerResponse.integrityDialogTypeCode()
    if (showDialogType != null) {
        // Call showDialog with type code, the dialog will be shown on top of the
        // provided activity and complete when the dialog is closed.
        val integrityDialogResponseCode: Task<Int> =
        tokenResponse.showDialog(activity, showDialogType)
        // Handle response code, call the Integrity API again to confirm that
        // verdicts have been resolved.
    }
    
    

    Java

    
    // Show dialog as indicated by the server
    @Nullable Integer showDialogType = yourServerResponse.integrityDialogTypeCode();
    if (showDialogType != null) {
      // Call showDialog with type code, the dialog will be shown on top of the
      // provided activity and complete when the dialog is closed.
      Task<Integer> integrityDialogResponseCode =
          tokenResponse.showDialog(activity, showDialogType);
      // Handle response code, call the Integrity API again to confirm that
      // verdicts have been resolved.
    }
    
    
  5. กล่องโต้ตอบจะแสดงทับกิจกรรมที่ให้ไว้ เมื่อผู้ใช้มี ปิดกล่องโต้ตอบ งานจะมีรหัสการตอบกลับเสร็จสมบูรณ์

  6. (ไม่บังคับ) ขอโทเค็นอื่นเพื่อแสดงกล่องโต้ตอบเพิ่มเติม หากคุณให้ คำขอมาตรฐาน คุณจะต้องเตรียมความพร้อม ผู้ให้บริการโทเค็นอีกครั้งเพื่อรับผลการตัดสินใหม่