The WeChat mini program provides two integration methods: plug-in docking and SDK docking. Please select the appropriate docking method according to the comparison below
Comparison between plug-in and SDK:
- Plug-in code does not directly provide SDK source code, does not occupy a mini program volume
- After the new version of the plug-in is released, the manager of the mini program will receive the update notification and can experience the new version of the plug-in and update the mini program. The mini-program release does not need to be reviewed again
- Mini program can call plug-ins, and plug-ins can no longer call other plug-ins
- Plugins do not support earlier versions of 8-digit applets with Appids
Plug-in version
1.1 Mini program management background add plug-in
- Login Log in to the Open platform console(https://open.alipay.com/develop/manage) to access the plug-in service under development
- Click to order additional plug-ins
- Search for 设备指纹插件, select plug-in, click Order, and confirm to obtain the plug-in
- Select the authorization and bind the applet
1.2 Integrate mini program code
1.app.json declares the plugin
{
"plugins": {
"tdfp-plugin": {
"version": "*", // Alipay plug-in currently only supports setting *, automatically selects the version, which version can be configured in the background
"provider": "2021003160688029"
}
},
}
- Note: The tripartite framework can be added accordingly. For example, in uni-app, you can add the above declaration to the
mp-alipay
module of the manifest.json file
- Reference plug-in &&necessary configuration
Reference plug-in, For example, in pages/index/index.js, the plugin and global variables are referenced at the top of the file:
const plugin = requirePlugin('tdfp-plugin')
const app = getApp()
Configuration
In app.js
, partnerCode
is required and appName
and channel
are optional
App({
......
globalData: {
......
_fmOpt: {
partnerCode: "", // Please fill in your partner code
appName: "", // Please fill in your app name
channel: "",// Please fill in your channel
env: "PRODUCTION"
}
}
})
- Get BlackBox
After the device fingerprint object is initialized, the device information can be obtained. Our device fingerprint SDK adopts a call mode similar to WeChat API and supports passingsuccess
,fail
,complete
callback, and other configuration fields:
var that = this
var fmagent = new plugin.FMAgent(app.globalData._fmOpt)
fmagent.getInfo({
page: that,
mode:'plugin',
// If you have the unionid function enabled, pass in the encrypted user unionid
// Please pass in the encrypted openid of the user (ensure that the encrypted openid is one-to-one corresponding to the original openid).
unionid: '',
success: function (res) {},//Successful callback, res is BlackBox string
fail: function (res) {},// Failure callback, res for various exception objects
complete: function (res) {} // Complete callback, res for BlackBox string or various exception objects
})
2. SDK Mode
1. Adding a Domain Name
In Settings
- development Settings
- server domain
request legal domain
add:
Environment | Domain name |
---|---|
Production(required) | https://fp.tongdun.net |
Note:
- If the online version applet will only access the same production environment, add the first production domain name
- The Fingerprint SDK for Tongdun Alipay mini program devices only supports wechat clients with the version of the client base library (SDKVersion, obtained through wx.getSystemInfo API) above 1.20.0
2. Insert canvas node
Import in the corresponding axml
file that needs to call the sdk
<view>
<canvas id='tdcanvas' style="visibility: hidden;position: fixed;z-index: -999;left: 9999px;"></canvas>
</view>
Note: You are advised to introduce it as a component
3. Initialization
Introduce, on the page you want to use, For example, in pages/index/index.js
, first reference the SDK file at the top of the file:
import FMAgent from '../../fmsdk/fm-xxx-es.min.js'
Configuration of FMAgent
In the globalData
of the app
object in the app.js
file
App({
......
globalData: {
......
_fmOpt: {
partnerCode: "", // Please fill in your partner code
appName: "", // Please fill in your app name
channel: "", // Please fill in your channel
env: "PRODUCTION"
}
}
})
4. Get blackBox
After the device fingerprint object is initialized, the device information can be obtained. Our device fingerprint SDK adopts a call mode similar to wechat API, and supports passing success
, fail
, complete
callback, and other configuration fields:
var that = this
var fmagent = new FMAgent(app.globalData._fmOpt)
fmagent.getInfo({
page: that, // The Page or Component object where FMAgent resides
unionid: '', // User id
success: function (res) {
// Successful callback, res is blackBox string
},
fail: function (res) {
// Failure callback, res for various exception objects
},
complete: function (res) {
// Complete callback, res for BlackBox string or various exception objects
}
})
API Parameter Description
parameter | type | describe | sample | Required | Remove Field |
---|---|---|---|---|---|
page | Object | The page object or a component object that you are currently in | that | Yes | |
mode | String | docking mode(Please pass in' plugin' for plug-in access, and ignore the sdk mode) | 'plugin' | No | |
unionid | String | User unionid (remember that custom default value cannot be passed, no value please pass an empty string, otherwise collision will occur)) | No | ||
timeout | Number | Get BlackBox timeout (default: 2500, including the total duration of collecting and sending requests, range: 2500-16000,Unit: ms) | 6000 | No | |
getInfoType | String | Get blackbox mode ('1' : use cached blackbox first, '2' : use real-time collection blackbox first, '3' : use unexpired blackbox first to expire, default mode is '1') | '1' | No | |
getcliallowed | Boolean | Whether to collect the clipboard (some phones will have the system prompt that the clipboard has been collected, and the clipboard can partially enhance our recovery ability) The default is false | true | No | clipoard |
getLocationAllowed | Boolean | Whether to collect location information. (The default false is not collected, if you need to collect, please obtain the location information authorization of wechat and small programs in advance, and set the current item to true) | true | No | |
success | Function | Successful callback | function(res) {/res for BlackBox string /} | Yes | |
fail | Function | Failed callback | function(res) {/res for various exception objects /} | No | |
complete | Function | Complete callback | function(res) {/res for BlackBox string or various exception objects /} | No |