my.signContract

Use this API to redirect the user to the authorization page. After the user completes the authorization, the app will return the authorization code which can be used to obtain the access token for the agreement payment.

Note:

Please make sure you use the Appx with 1.24.6 or higher versions in order to use this API.

Below is a diagram that illustrates how the interaction works:

my.signContract

The merchant Mini Program server can call authorization consult API in step 2 to get the sign content with an authorization URL. Then the Mini Program will call the my.signContract JSAPI to invoke the authorization process. After the user completes the authorization, the Mini Program sends JSAPI result to its server so that the server can call apply token API to get accessToken.

Sample code

copy
my.signContract({
  signStr: 'https://openauth.xxx.com/authentication.htm?authId=FBF16F91-28FB-47EC-B9BE-27B285C23CD3',
  success: (res) => {
    my.alert({
    content: JSON.stringify(res),
  });
  },
  fail: (res) => {
    my.alert({
    content: JSON.stringify(res),
  });
  }
});

Parameters

PropertyType

Required

Description
signStrStringYesThis parameter is the authorization string returned by the app to further the authorization process.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

Success Callback Function

PropertyTypeDescription
authStateString The authorization status. It is generated in Mini Program server and sent to app server. The maximum length is 256. Refer here for details.
authCodeStringThe authorization code assigned by app which can be used to obtain the access token for the agreement payment. The maximum length is 32.

An example of a successfully returned message is as follows:

copy
{
	"authState":"663A8FA9-D836-48EE-8AA1-1FF682989DC7",
	"authCode":"663A8FA9D83648EE8AA11FF682989DC7"
}

Fail Callback Function

PropertyTypeDescription
errorStringThe error code for the failure.
errMessageStringThe error message.

Error Code

When error happens, the fail callback function will be executed. The error code can refer to the following table.

Error CodeDescription
6001User cancels the sign process.
6002The sign fails because of network error.
7001The result of the sign is unknown, it may be successful.
7002The sign fails.