English
Initialize JS API Runtime Environment
About 340 wordsAbout 1 min
2026-01-19
Import JS Files
- To use Fxiaoke JS API, you may reference the JS file directly in your webpage:
<!-- Fxiaoke JS API core file -->
<script src="http://www.fxiaoke.com/open/jsapi/2.1.3/fsapi.min.js"></script>Alternatively, download and host the file locally:
<!-- Fxiaoke JS API core file -->
<script src="/js/fsapi.min.js"></script>After loading, use the global FSOpen object to call APIs (e.g., FSOpen.runtime.getVersion).
- To use Fxiaoke UI Component Library, download both JS and CSS files. The decompressed package contains:
uikit.js/uikit.css(all components)- Individual component files in
/components(recommended for selective loading)
JS API Conventions
Standard parameter format:
{
"param1": "value1", // Interface parameter
"onSuccess": function(resp) {}, // Success callback
"onFail": function(error) {} // Error callback
}Success response format:
{
"result1": "data1" // Returned data
}Error response format:
{
"errorCode": 40000,
"errorMessage": "Invalid parameter"
}See Error Codes for details.
Initialize Runtime
FSOpen.init({
appId: 'FSAID_1313de7', // Required
timestamp: 1463564391382, // Required
nonceStr: 'HUsfdsOIIejfowe', // Required
signature: '1520C2C8223BC...',// Required (uppercase SHA-1)
onSuccess: function() {
// Proceed with API calls
},
onFail: function(error) {
if (error.errorCode === 30000) {
alert('Client upgrade required');
}
}
});Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| appId | String | Yes | Developer console ID |
| timestamp | Long | Yes | Unix timestamp |
| nonceStr | String | Yes | Random string (6-32 chars) |
| signature | String | Yes | Uppercase SHA-1 hash |
Signature Generation:
- Obtain
jsapi_ticket(valid 7200s, details) - Concatenate sorted parameters (ASCII order):
jsapi_ticket=xxx&noncestr=xxx×tamp=xxx&url=xxx - SHA-1 hash → uppercase hex string
Java Example:
// See original documentation for implementationNotes:
- Use server-side signing only
- URL excludes fragments (#)
- Reuse
nonceStr/timestampfrominit()
Error Handling
| Code | Description |
|---|---|
| 30000 | Unsupported client version (<5.4.0) |
| 30001 | Environment not initialized |
| 40001 | Invalid signature/ticket |
Full Example
<!DOCTYPE html>
<html>
<head>
<!-- FS UI Kit -->
<link rel="stylesheet" href="assets/css/uikit.css" />
<script src="assets/js/uikit.js"></script>
<!-- FS API -->
<script src="http://www.fxiaoke.com/open/jsapi/2.0.0/fsapi.min.js"></script>
</head>
<body>
<!-- Page content -->
<script>
FSOpen.init({
appId: 'FSAID_1313de7',
timestamp: 1463564391382,
nonceStr: 'HUsfdsOIIejfowe',
signature: '1520C2C8223BC...',
onSuccess: function() {
// API calls here
}
});
</script>
</body>
</html>