Android app access to the wide-point Statistics API Solution

Source: Internet
Author: User
Tags base64 python script

The official reference to your document, very nonsense, is a C + + and Python script:

Android Java code access is as follows:

Package Com.edaixi.util;import Java.io.unsupportedencodingexception;import Java.net.socketexception;import Java.net.urlencoder;import Java.security.messagedigest;import Android.annotation.suppresslint;import Android.content.context;import Android.telephony.telephonymanager;import Com.lidroid.xutils.httputils;import Com.lidroid.xutils.exception.httpexception;import Com.lidroid.xutils.http.responseinfo;import Com.lidroid.xutils.http.callback.requestcallback;import Com.lidroid.xutils.http.client.HttpRequest.HttpMethod; public class Tecentadsutil {private static Context Mcontext;public tecentadsutil (context Mcontext) {super (); Tecentadsutil.mcontext = Mcontext;} @SuppressWarnings ("deprecation") public void Gettotencentads () throws SocketException {String Encrypt_key = "********** ***"; String imeistring = Getdeviceimei (); String timestring = GetSystemTime (); String query_string;try {query_string = "muid=" + urlencoder.encode (imeistring, "UTF-8") + "&conv_time=" + URLEncoder . Encode (TimeString, "UTF-8 "); String page = "Http://t.gdt.qq.com/conv/app/appid" + "/conv?" + query_string; String encode_page = urlencoder.encode (page, "UTF-8"); String property = "encrypt_key&get&" + encode_page; String Signature = String2md5 (property); String Base_data = query_string + "&sign=" + urlencoder.encode (signature, "UTF-8"); String base64 = ToBase64 (Base_data, Encrypt_key); String data = new String (Base64util.encode (Base64.getbytes ())); String attachment = "conv_type=" + urlencoder.encode ("Mobileapp_activite", "UTF-8") + "&app_type=" + Urlencoder.encode ("ANDROID", "UTF-8") + "&advertiser_id=" + urlencoder.encode ("673411", "UTF-8"); final String FinalURL = "http://t.gdt.qq.com/conv/app/1104311868/conv?v=" + Data + "&" + attachment; Httputils http = new Httputils (); Http.configtimeout (+); Http.send (Httpmethod.get, FinalURL, new requestcallback& Lt String> () {@Overridepublic void OnStart () {} @Overridepublic void OnFailure (HttpException arg0, String result) {}@ overridepublic void ONsuccess (responseinfo<string> result) {LOGUTIL.E ("= = = The result of the return = = = =" +result.result);});} catch (Unsupportedencodingexception e) {e.printstacktrace ();}} @SuppressLint ("Defaultlocale") public static string Getdeviceimei () {String IMEI = ((Telephonymanager) Mcontext.getsystemservice (Context.telephony_service)). Getdeviceid (); return String2md5 (Imei.tolowercase ());} Gets the current timestamp public static String GetSystemTime () {Long time = System.currenttimemillis ()/1000;return time + "";} MD5 Tool class public static string String2md5 (String inStr) {MessageDigest MD5 = null;try {MD5 = messagedigest.getinstance ("MD5 ");} catch (Exception e) {System.out.println (e.tostring ()); E.printstacktrace (); return "";} char[] Chararray = Instr.tochararray (); byte[] ByteArray = new Byte[chararray.length];for (int i = 0; i < Chararray.leng Th i++) Bytearray[i] = (byte) chararray[i];byte[] md5bytes = Md5.digest (ByteArray); StringBuffer hexvalue = new StringBuffer (); for (int i = 0; i < md5bytes.length; i++) {int val = ((int) mD5bytes[i]) & 0xff;if (Val <) hexvalue.append ("0"); Hexvalue.append (Integer.tohexstring (Val));} return hexvalue.tostring ();} Base64 Utility class public static string ToBase64 (String base_data, String encrypt_key) {char[] Base_datachar = Base_data.tochara Rray (); char[] Base_datacharbak = new char[base_datachar.length];char[] Encrypt_keychar = Encrypt_key.tochararray (); Int j = 0;for (int i = 0; i < base_datachar.length; i++) {Base_datacharbak[i] = (char) (Base_datachar[i] ^ encrypt_keyc HAR[J]); j = (++j)% (encrypt_keychar.length);} return new String (Base_datacharbak);}}

  

Package Com.edaixi.util;import Java.io.unsupportedencodingexception;public class Base64util {private static char[] Base64encodechars = new char[] {' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ', ' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ', ' w ', ' x ', ' y ', ' z ', ' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' + ', '/'};p rivate static by te[] Base64decodechars = new byte[] {-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,- 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1, 1, 1, 62, 1, 1, 1, 63  6, 57, 58, 59, 60, 61,-1,-1,-1,-1,-1,-1,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,  21, 22, 23, 24, 25, -1,-1,-1,-1,-1,-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,-1, 1, -1,-1,-1};p ublic static String encode (byte[] data) {StringBuffer SB = new StringBuffer (); int len = Data.length;int i =  0;int B1, B2, B3;while (i < len) {B1 = data[i++] & 0xff;if (i = = len) {sb.append (base64encodechars[b1 >>> 2]); Sb.append (base64encodechars[(B1 & 0x3) << 4]); Sb.append ("= ="); break;} B2 = data[i++] & 0xff;if (i = = len) {sb.append (base64encodechars[b1 >>> 2]); Sb.append (base64encodechars[( B1 & 0x03) << 4) | ((B2 & 0xf0) >>> 4)]); Sb.append (base64encodechars[(B2 & 0x0f) << 2]); Sb.append ("="); break;} B3 = data[i++] & 0xff;sb.append (BASE64ENCODECHARS[B1 >>> 2]); Sb.append (base64encodechars[(B1 & 0x03) << 4) | ((B2 & 0xf0) >>> 4)]); Sb.append (base64encodechars[(B2 & 0x0f) << 2) | ((B3 & 0xc0) >>> 6)]); Sb.append (Base64encodechars[b3 & 0x3f]);} return sb.tostring ();} public static byte[] Decode (String str) throws Unsupportedencodingexception {STRINGBUffer sb = new StringBuffer (); byte[] data = str.getbytes ("Us-ascii"); int len = Data.length;int i = 0;int B1, B2, B3, B4;wh Ile (I < len) {/* B1 */do {b1 = base64decodechars[data[i++]];} while (I < len && B1 = =-1); if (B1 = = 1) Brea k;/* b2 */do {b2 = base64decodechars[data[i++]];} while (I < len && B2 = = 1); if (B2 = = 1) break;sb.append ((Cha R) ((B1 << 2) | ((B2 & 0x30) >>> 4))); * B3 */do {b3 = data[i++];if (B3 = =) return sb.tostring (). GetBytes ("iso-8859-1"); b3 = Base64decodechars[b3];} while (I & Lt Len && B3 = =-1); if (B3 = =-1) break;sb.append ((char) (((B2 & 0x0f) << 4) | ((B3 & 0x3c) >>> 2))); * B4 */do {b4 = data[i++];if (B4 = =) return sb.tostring (). GetBytes ("iso-8859-1"); b4 = Base64decodechars[b4];} while (I & Lt Len && B4 = =-1); if (B4 = =-1) break;sb.append ((char) (((B3 & 0x03) << 6) | b4));} Return sb.tostring (). GetBytes ("Iso-8859-1");}}

  

Android app access to the wide-point Statistics API Solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.