To facilitate the verification of the device onboarding process, we provide tools that assist developers in generating keys and device signatures. Both Shell and Java versions are available.
Note: The tools provided here are solely intended to help developers verify processes and demonstrate related algorithms. They are suitable only for debugging and development reference purposes and are not recommended for production environments. Developers are advised to perform secondary development based on their specific use cases.
1. Retrieve the Tool
- It is recommended to use it in a Linux or Mac OS environment. Please ensure that OpenSSL is installed on your local machine, and version v1.1.1 is recommended.
- The device signature should be embedded in the secure area of the device before shipment, or used on the device after being signed on the server side and delivered. Do not perform the signing process on the device.
Shell Script Sample Code
Java Sample Code
You can integrate it in the following ways:
- Jar package: Download wmpf-signup-device-multi-platform-util-jvm-0.0.1.jar and integrate it into your Java project.
- Source code: You can also compile the tool yourself using the address and command below.
- Source code address
- Compile and publish to Maven local:
./gradlew publishtomavenlocal - Source jar
In addition, you need to add the following dependencies to your project:
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72com.squareup.okhttp3:okhttp:4.7.2com.google.code.gson:gson:2.8.6org.jetbrains.kotlin:kotlin-stdlib-common:1.3.72
2. Key Generation
The generated public key must be uploaded to the WeChat Terminal Cooperation Platform to obtain the KeyVersion. The private key will be used to generate device signatures.
shell
sudo bash ./mmiot_ecdsa_sign.sh gen_ecdsa_key prikey_filepath pubkey_filepath
For example:

Upon successful execution, the terminal outputs gen_ecdsa_key succ prikey_path:prikey_filepaht pubkey_path:pubkey_filepath, and two files are generated in the corresponding directory, saving the public key and private key respectively.
Java
// Set the working directory for this script
WmpfDeviceSignUpUtil.workingDir = System.getProperty("java.io.tmpdir")
// Generate the private and public key pair
// If you already have a key pair, name the files wmpfPublicKeyPath.key and wmpfPrivateKeyPath.key respectively, and place them in the workingDir. The script will automatically load them.
// If no key pair is found in the workingDir, the script will automatically generate one.
val (privateKey, publicKey) = WmpfDeviceSignUpUtil.getPrivateKeyPublicKeyPair()
println("private key = [$privateKey]")
println("public key = [$publicKey]")
3. Generate Device Signature
shell
Call the mmiot_ecdsa_sign tool, inputting ProductId, deviceId, and the private key file, to generate the signature Signature for each device.
sudo bash ./mmiot_ecdsa_sign.sh gen_ecdsa_sign ProductId my_deivice_id prikey_filepath sign_filepath
sign_filepath is the path where you want to output the Signature, for example /Users/mine/Desktop/sign/sign_file. The path specifies a file for output, not a folder.
Example:
You can see that after executing the tool, the terminal outputs gen_ecdsa_sign succ sign_file_path:sign_filepath, and the signature file for this device is generated at the specified path.
Verify Device Signature
sudo bash ./mmiot_ecdsa_sign.sh verify_ecdsa_sign ProductId my_device_id pubkey_filepath sign_filepath
Example:

Java
val productId = "your-product-id-from-we-cooper"
val deviceId = "your-customized-device-id"
// TODO Upload the public key to the "WeChat Terminal Cooperation Platform"
// Get the Signature
val signature = WmpfDeviceSignUpUtil.getSignature(
productId,
deviceId,
privateKey
)
println("signature = [$signature]")
// Verify the signature
if (
WmpfDeviceSignUpUtil.verifySignature(
productId,
deviceId,
publicKey,
signature
)
) {
println("verifySignature success")
} else {
println("verifySignature fail")
}
4. Device Registration
The Java sample code also provides a reference implementation for registering devices via the WeChat Admin Console Register Device.
Java
val deviceInfo = DeviceInfo()
deviceInfo.model_name = "your-model-name"
deviceInfo.product_id = productId
deviceInfo.device_id_list = Array(1) { deviceId }.toList()
// Get accessToken
// Input parameters: appId of the mobile app registered on the WeChat Open Platform, mobile app appSecret
val accessTokenResp =
WmpfDeviceSignUpUtil.getAccessToken("your-app-id", "your-app-secret")
if (accessTokenResp.errcode == 0) {
println("access token [${accessTokenResp.access_token}] expires = " + accessTokenResp.expires_in)
// Add device information to the WeChat backend
val resp = WmpfDeviceSignUpUtil.addDevicesToWeChatServer(
accessToken = accessTokenResp.access_token,
deviceInfo = deviceInfo
)
if (resp.errcode == 0) {
println("addDevicesToWeChatServer resp success")
}
} else {
println("get access token fail code = ${accessTokenResp.errcode}, msg = ${accessTokenResp.errmsg}")
}