格式: {
"appid": 1,
"promoter": "sample string 2",
"timestamp": 3,
"sign": "sample string 4",
"para": {
"dev_guid": "sample string 1",//设备GUID
"dev_memory": 2,//设备内存
}
}
创建对象
"appid": 1,
"promoter": "sample string 2",
"timestamp": 3,
"sign": "sample string 4",
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(Initparameters.APP_ID, SSSParams.getAppid());
jsonObject.put(Initparameters.PROMOTER,SSSParams.getPromoter());
jsonObject.put(Initparameters.TIMESTAMP, timestamp);
jsonObject.put(Initparameters.SIGN, sign);
jsonObject.put(Initparameters.PARA, obj);
} catch (JSONException e) {
e.printStackTrace();
}
Log.e("sendInterfaceObj", jsonObject.toString() );
return jsonObject.toString();
}
"para": {
"dev_guid": "sample string 1",//设备GUID
"dev_memory": 2,//设备内存
}
JSONObject objPara = new JSONObject();
try {
objPara.put(co.sss.sdklibrary.param.Initparameters.DEV_GUID, dev_guid);
objPara.put(co.sss.sdklibrary.param.Initparameters.DEV_MEMORY, dev_memory);
} catch (JSONException e) {
e.printStackTrace();
}
得到所有的参数 然后请求网络 urlxxxxxxxx
/**
* 这里向服务器 验证sdk是否初始化成功
* */
HttpUtils.http(activity, Initparameters.GetInstance().INIT_URL(), requestbody, new VolleyInterface() {
@Override
public void sucess(JSONObject result) {
String initjson = result.toString(); //得到字符串
Gson gson = new Gson(); //解析
Init initModule = gson.fromJson(initjson, Init.class); 返回状态码
LogUtils.e("初始化状态码", initModule.getRet()+"");
if (initModule.getRet()==0){
Toast.makeText(activity, "初始化成功!", Toast.LENGTH_SHORT).show();
//发给广播(传递给用户)
Intent intent = new Intent();
intent.setAction("SSSSDK");
intent.putExtra("SDk_INIT_DATA", initjson);
activity.sendBroadcast(intent);
//这里设置标识是为了,广播接收时区分谁发送的广播
Flags.FLAG=1;
Flags.INIT_IS_SUECSS_FAILD=100;
} else {
Toast.makeText(activity, "初始化失败!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setAction("xxxx");
intent.putExtra("SDk_INIT_DATA", result.toString());
activity.sendBroadcast(intent);
Flags.FLAG=1;
Flags.INIT_IS_SUECSS_FAILD=101;
// LogUtils.e("InitSdk>>>>>>>>>>>", initModule.getRet() + "....");//
}
}
@Override
public void error(String result) {
LogUtils.e("初始化网络请求失败信息",result);
Intent intent = new Intent();
intent.setAction("xxxxx");
intent.putExtra("SDk_INIT_DATA", result);
activity.sendBroadcast(intent);
Flags.FLAG=1;
}
});
"appid": 1,
"promoter": "sample string 2",
"timestamp": 3,
"sign": "sample string 4",
"para": {
"dev_guid": "sample string 1",//设备GUID
"dev_memory": 2,//设备内存
}
}
创建对象
"appid": 1,
"promoter": "sample string 2",
"timestamp": 3,
"sign": "sample string 4",
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(Initparameters.APP_ID, SSSParams.getAppid());
jsonObject.put(Initparameters.PROMOTER,SSSParams.getPromoter());
jsonObject.put(Initparameters.TIMESTAMP, timestamp);
jsonObject.put(Initparameters.SIGN, sign);
jsonObject.put(Initparameters.PARA, obj);
} catch (JSONException e) {
e.printStackTrace();
}
Log.e("sendInterfaceObj", jsonObject.toString() );
return jsonObject.toString();
}
"para": {
"dev_guid": "sample string 1",//设备GUID
"dev_memory": 2,//设备内存
}
JSONObject objPara = new JSONObject();
try {
objPara.put(co.sss.sdklibrary.param.Initparameters.DEV_GUID, dev_guid);
objPara.put(co.sss.sdklibrary.param.Initparameters.DEV_MEMORY, dev_memory);
} catch (JSONException e) {
e.printStackTrace();
}
得到所有的参数 然后请求网络 urlxxxxxxxx
/**
* 这里向服务器 验证sdk是否初始化成功
* */
HttpUtils.http(activity, Initparameters.GetInstance().INIT_URL(), requestbody, new VolleyInterface() {
@Override
public void sucess(JSONObject result) {
String initjson = result.toString(); //得到字符串
Gson gson = new Gson(); //解析
Init initModule = gson.fromJson(initjson, Init.class); 返回状态码
LogUtils.e("初始化状态码", initModule.getRet()+"");
if (initModule.getRet()==0){
Toast.makeText(activity, "初始化成功!", Toast.LENGTH_SHORT).show();
//发给广播(传递给用户)
Intent intent = new Intent();
intent.setAction("SSSSDK");
intent.putExtra("SDk_INIT_DATA", initjson);
activity.sendBroadcast(intent);
//这里设置标识是为了,广播接收时区分谁发送的广播
Flags.FLAG=1;
Flags.INIT_IS_SUECSS_FAILD=100;
} else {
Toast.makeText(activity, "初始化失败!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setAction("xxxx");
intent.putExtra("SDk_INIT_DATA", result.toString());
activity.sendBroadcast(intent);
Flags.FLAG=1;
Flags.INIT_IS_SUECSS_FAILD=101;
// LogUtils.e("InitSdk>>>>>>>>>>>", initModule.getRet() + "....");//
}
}
@Override
public void error(String result) {
LogUtils.e("初始化网络请求失败信息",result);
Intent intent = new Intent();
intent.setAction("xxxxx");
intent.putExtra("SDk_INIT_DATA", result);
activity.sendBroadcast(intent);
Flags.FLAG=1;
}
});