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.
System requirement
Follow the system requirement below based on your wallet app:
- Alipay China 10.2.38 or above. If the version is earlier, we recommend you try to implement compatibility.
- For other wallet apps, contact the technical support of your wallet.
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:
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
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
Property | Type | Required | Description |
signStr | String | Yes | This parameter is the authorization string returned by the app to further the authorization process. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
Success callback function
Property | Type | Description |
authState | String | The authorization status. It is generated in mini program server and sent to app server. The maximum length is 256. Refer to here for details. |
authCode | String | The authorization code assigned by app which can be used to obtain the access token for the agreement payment. The maximum length is 32. |
Note: For the mini programs that are launched to Alipay China, the success callback function will not contain the above properties.
An example of a successfully returned message is as follows:
{
"authState":"663A8FA9-D836-48EE-8AA1-1FF682989DC7",
"authCode":"663A8FA9D83648EE8AA11FF682989DC7"
}
Fail callback function
Property | Type | Description |
error | String | The error code for the failure. |
errMessage | String | The error message. |
Error code
When error happens, the fail callback function will be executed. The error code can refer to the following table.
Error Code | Description |
6001 | User cancels the sign process. |
6002 | The sign fails because of network error. |
7001 | The result of the sign is unknown. It may be successful. |
7002 | The sign fails. |