table of Contents
Foreword
The company has developed several small programs, small programs for easy viewing all data in real-time visitor, the official called directly query interface.
Call interface, the need to manually obtain a signature, the following is the summary of the process.
- Tencent Mobile Data URL: https://mta.qq.com/
- Small micro-channel program data api documentation: https://mta.qq.com/docs/wechat_mini_program_api.html
Small micro-channel data access program
Official signature
Java version Tools
Note that this is the time stamp
timestamp
in seconds.
- method
/**
* @Author luohongquan
* @Description 获取微信小程序分析接入接口签名: https://mta.qq.com/docs/wechat_mini_program_api.html
* @Date 15:12 2019/12/20
* @Param [appId, secretKey, timestamp, startTime, endTime]
* @return java.lang.String
*/
public static String getWxAppDataSign(String appId, String secretKey, String timestamp, String startTime, String endTime) {
long a = Calendar.getInstance().getTimeInMillis();
String signStr = String.format(TencentMobileConstant.SIGN_TEMPLATE, secretKey, appId, endTime, startTime, timestamp);
String sign = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(signStr.getBytes());
byte[] resultByteArray = md.digest();
sign = new BigInteger(1, resultByteArray).toString(16);
} catch (Exception e) {
e.printStackTrace();
}
return sign;
}
- test
public static void main(String[] args) {
String appId = "xxxx"; // 你的小程序appId
String secretKey = "xxxxxxxxxxxxxxxxxxxxx"; // 你的小程序secretKey
long a = Calendar.getInstance().getTimeInMillis();
String timestamp = String.valueOf(a/1000); // 秒
String startTime = "2019-12-20";
String endTime = "2019-12-20";
String sign = getWxAppDataSign(appId, secretKey, timestamp, startTime,endTime);
}
After acquiring signature, get access request
https://openapi.mta.qq.com/wx/v1/analytics/period?start_time=2019-12-20&end_time=2019-12-20×tamp=1576808602&app_id=xxxx&sign=3a26dd3d76bcb12d2a55fe253995exxx
, to obtain the data.