号簿助手 v4.6.31版本的 MD5 值为:9d7ff98a6bb5cc178eac2df4d1b2f0e0
以下内容为反编译后的 YellowPageApiImpl.java 源代码,内容仅作参考
package com.yulore.superyellowpage.impl;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.chinatelecom.pim.core.sqlite.SuperNumberConstants;
import com.ricky.android.common.http.NetUtils;
import com.ricky.android.common.http.RequestVo;
import com.ricky.android.common.pool.ThreadManager;
import com.ricky.android.common.utils.Logger;
import com.ricky.android.common.utils.SharedPreferencesUtility;
import com.yulore.superyellowpage.AsyncDataCallback;
import com.yulore.superyellowpage.PkgDecoderApi;
import com.yulore.superyellowpage.YellowPageApi;
import com.yulore.superyellowpage.activity.AlertActivity;
import com.yulore.superyellowpage.activity.CategoryListActivity;
import com.yulore.superyellowpage.activity.NearlyListActivity;
import com.yulore.superyellowpage.activity.NewShopDetailActivity;
import com.yulore.superyellowpage.activity.ServiceActivity;
import com.yulore.superyellowpage.app.ApplicationMap;
import com.yulore.superyellowpage.biz.LogicBizFactory;
import com.yulore.superyellowpage.db.biz.CustomDaoBiz;
import com.yulore.superyellowpage.db.biz.DAOBizFactory;
import com.yulore.superyellowpage.db.biz.DianPingDaoBiz;
import com.yulore.superyellowpage.db.biz.GrouponDaoBiz;
import com.yulore.superyellowpage.impl.YuloreApiFactory;
import com.yulore.superyellowpage.modelbean.ActionMenu;
import com.yulore.superyellowpage.modelbean.Category;
import com.yulore.superyellowpage.modelbean.City;
import com.yulore.superyellowpage.modelbean.CustomMenu;
import com.yulore.superyellowpage.modelbean.CustomService;
import com.yulore.superyellowpage.modelbean.HomeEntity;
import com.yulore.superyellowpage.modelbean.OfflinePkgInfos;
import com.yulore.superyellowpage.modelbean.Promotion;
import com.yulore.superyellowpage.modelbean.RecognitionTelephone;
import com.yulore.superyellowpage.modelbean.SearchEntity;
import com.yulore.superyellowpage.modelbean.ShopItem;
import com.yulore.superyellowpage.modelbean.YuloreLocation;
import com.yulore.superyellowpage.parser.AddressParser;
import com.yulore.superyellowpage.parser.CustomServiceParser;
import com.yulore.superyellowpage.utils.CipherUtil;
import com.yulore.superyellowpage.utils.Constant;
import com.yulore.superyellowpage.utils.FileUtil;
import com.yulore.superyellowpage.utils.Utils;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.cookie.SM;
import org.json.JSONException;
public class YellowPageApiImpl implements YellowPageApi {
private static final String TAG = YellowPageApiImpl.class.getSimpleName();
private Context context;
private SearchEntity merchants;
private SharedPreferencesUtility sp;
public YellowPageApiImpl(Context context) {
this.context = context;
this.sp = LogicBizFactory.createSharedPreferencesUtility(context);
}
@Override
public YuloreLocation queryAddressByGeo(double lng, double lat, int type) {
checkAKValidity();
RequestVo reqVo = new RequestVo();
reqVo.context = this.context;
HashMap<String, String> headers = new HashMap<>();
headers.put(SM.COOKIE, Utils.setCookie(this.context));
reqVo.headers = headers;
reqVo.requestUrl = Constant.APP_HOST.concat(Constant.ADDRESS_API).concat("?lng=").concat(String.valueOf(lng)).concat("&lat=").concat(String.valueOf(lat)).concat("&apikey=").concat(Constant.API_KEY).concat("&app=").concat(Constant.APP_NAME).concat("&uid=").concat(Constant.GLOBLE_DEVICE_ID).concat("&city=" + type).concat("&coord=").concat(Constant.locationmode == YuloreApiFactory.LocationMode.YULORELOCATION ? "wgs-84" : "gcj-02");
reqVo.connectionTimeout = 5000;
YuloreLocation addr = null;
try {
String result = NetUtils.get(reqVo);
if (!TextUtils.isEmpty(result) && (addr = new AddressParser().parseJSON(result)) != null) {
addr.setLatitude(lat);
addr.setLongitude(lng);
}
} catch (SocketTimeoutException e) {
e.printStackTrace();
} catch (ClientProtocolException e2) {
e2.printStackTrace();
} catch (IOException e3) {
e3.printStackTrace();
} catch (JSONException e4) {
e4.printStackTrace();
}
return addr;
}
@Override
public CustomService queryCustomService(final String shopId, final AsyncDataCallback<CustomService> callback) {
CustomService service = LogicBizFactory.createShopDetailBiz(this.context).requestCustomService(shopId);
ThreadManager.getInstance().getLongPool().execute(new Runnable() {
@Override
public void run() {
try {
CustomService customService = YellowPageApiImpl.this.queryCustomService(shopId);
callback.requestSuccess(customService);
} catch (ClientProtocolException e) {
callback.requestFailed(e);
} catch (IOException e2) {
callback.requestFailed(e2);
} catch (JSONException e3) {
callback.requestFailed(e3);
} catch (Exception e4) {
e4.printStackTrace();
}
}
});
return service;
}
@Override
public CustomService queryCustomService(String shopId) throws ClientProtocolException, IOException, JSONException {
if (shopId == null) {
return null;
}
checkAKValidity();
String sg = Constant.API_SECRET.substring(89, 129);
RequestVo reqVo = new RequestVo();
reqVo.context = this.context;
HashMap<String, String> headers = new HashMap<>();
headers.put(SM.COOKIE, Utils.setCookie(this.context));
reqVo.headers = headers;
StringBuffer sb = new StringBuffer();
sb.append(sg.substring(0, 9)).append(shopId).append(sg.substring(9, 24)).append(Constant.GLOBLE_DEVICE_ID).append(sg.substring(24, 31)).append(shopId).append(sg.substring(31));
String md5 = CipherUtil.md5(sb.toString());
reqVo.requestUrl = Constant.APP_HOST.concat(Constant.SERVICE_API).concat("?shopid=").concat(shopId).concat("&uid=").concat(Constant.GLOBLE_DEVICE_ID).concat("&apikey=").concat(Constant.API_KEY).concat("&sig=").concat(md5.substring(4, 36));
reqVo.connectionTimeout = Constant.NUBIA_REQUEST_TOKEN;
try {
String result = NetUtils.get(reqVo);
CustomService customService = new CustomServiceParser().parseJSON(String.valueOf(result) + "|||" + shopId);
if (customService != null) {
GrouponDaoBiz grouponDaoBiz = DAOBizFactory.createGrouponDaoBiz(this.context);
CustomDaoBiz customDaoBiz = DAOBizFactory.createCustomDaoBiz(this.context);
DianPingDaoBiz dianPingDaoBiz = DAOBizFactory.createDianPingDaoBiz(this.context);
if (customService.getGrouponList() != null && customService.getGrouponList().size() > 0) {
if (grouponDaoBiz.getAllGrouponByShopId(shopId) != null && grouponDaoBiz.getAllGrouponByShopId(shopId).size() > 0) {
grouponDaoBiz.delete(shopId);
}
grouponDaoBiz.insertGrouponBatch(customService.getGrouponList(), shopId);
} else if (grouponDaoBiz.getAllGrouponByShopId(shopId) != null && grouponDaoBiz.getAllGrouponByShopId(shopId).size() > 0) {
grouponDaoBiz.delete(shopId);
}
if (customService.getCustomList() != null && customService.getCustomList().size() > 0) {
if (customDaoBiz.getAll(shopId) != null && customDaoBiz.getAll(shopId).size() > 0) {
customDaoBiz.delete(shopId);
}
List<CustomMenu> list = customService.getCustomList();
CustomMenu[] customs = new CustomMenu[list.size()];
int j = list.size();
for (int i = 0; i < j; i++) {
customs[i] = list.get(i);
}
customDaoBiz.generalInsert(customs, shopId);
} else if (customDaoBiz.getAll(shopId) != null && customDaoBiz.getAll(shopId).size() > 0) {
customDaoBiz.delete(shopId);
}
if (customService.getComments() != null && customService.getComments().getReview_id() > 0) {
dianPingDaoBiz.insertDianPingBean(customService.getComments(), shopId);
} else if (dianPingDaoBiz.getDianPingBeanByShopId(shopId) != null && dianPingDaoBiz.getDianPingBeanByShopId(shopId).getReview_id() > 0) {
dianPingDaoBiz.delete(shopId);
}
if (TextUtils.isEmpty(customService.getCustomUrl()) && !TextUtils.isEmpty(DAOBizFactory.createCustomDetailDaoBiz(this.context).find(shopId))) {
DAOBizFactory.createCustomDetailDaoBiz(this.context).delete(shopId);
return customService;
}
DAOBizFactory.createCustomDetailDaoBiz(this.context).insert(customService.getCustomUrl(), shopId);
return customService;
}
return customService;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public String getDetailWebUrl(String shopId) {
checkAKValidity();
StringBuffer params = new StringBuffer();
params.append("apikey=").append(Constant.API_KEY);
params.append("&app=").append(Constant.APP_NAME);
params.append("&uid=").append(Constant.GLOBLE_DEVICE_ID);
return Constant.H5_DETAIL_API.concat(shopId).concat("?").concat(params.toString());
}
protected void checkAKValidity() {
if (TextUtils.isEmpty(Constant.API_KEY) || TextUtils.isEmpty(Constant.API_SECRET)) {
throw new IllegalArgumentException("API_KEY or API_SECRET must not be null,have you called YuloreApiFactory's registerAK method ?");
}
}
@Override
public String getCorrectionWebUrl(String shopId, String telNumber) {
checkAKValidity();
return TextUtils.isEmpty(shopId) ? "" : String.valueOf(Constant.H5_CORRECT_API.concat("?sid=").concat(shopId).concat("&tel=").concat(telNumber).concat("&apikey=")) + Constant.API_KEY;
}
@Override
public HomeEntity requestHomeEntityData() {
return LogicBizFactory.createHomeDataBiz(this.context).getLocalHomeData();
}
@Override
public HomeEntity requestHomeEntityData(AsyncDataCallback<HomeEntity> listener) {
return LogicBizFactory.createHomeDataBiz(this.context).getLocalHomeData(listener);
}
@Override
public void startActivityByPromotion(Activity activity, Promotion promotion) {
ActionMenu menu = promotion.getActionMenu();
if (menu != null) {
Intent in = Utils.createIntent(menu.getAction(), menu.getCategory(), menu.getData(), menu.getType(), menu.getPackageName());
Utils.startActivity(activity, in, null);
}
}
@Override
public void startActivityByUrl(Context context, String url, String title) {
if (!TextUtils.isEmpty(url)) {
if (url.startsWith("yulorepage-sendsms")) {
Intent intent = new Intent(context, (Class<?>) AlertActivity.class);
intent.addFlags(67108864);
context.startActivity(intent);
return;
}
if (url.startsWith("yulorepage-list:")) {
if (url.contains("o=2")) {
Intent intent2 = new Intent(context, (Class<?>) NearlyListActivity.class);
intent2.putExtra("link", url);
intent2.addFlags(335544320);
if (title != null) {
intent2.putExtra("title", title);
}
context.startActivity(intent2);
return;
}
Intent intent3 = new Intent(context, (Class<?>) CategoryListActivity.class);
intent3.putExtra("link", url);
intent3.addFlags(67108864);
if (title != null) {
intent3.putExtra("title", title);
}
context.startActivity(intent3);
return;
}
if (url.startsWith(HttpHost.DEFAULT_SCHEME_NAME)) {
Intent intent4 = new Intent(context, (Class<?>) ServiceActivity.class);
intent4.putExtra("link", url);
TextUtils.isEmpty(title);
intent4.addFlags(335544320);
this.sp.putString(Constant.FORWARD_URL, Constant.RESOURCE_API + this.sp.getInt("currentCityId", 0));
context.startActivity(intent4);
return;
}
throw new IllegalArgumentException("url is not in conformity with the specification.");
}
throw new IllegalArgumentException("url is null.");
}
@Override
public void startDetailActivity(Activity activity, ShopItem shopItem) {
if (shopItem == null) {
throw new RuntimeException("shopItem is null.");
}
Intent intent = new Intent(this.context, (Class<?>) NewShopDetailActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable("shopItem", shopItem);
intent.putExtras(bundle);
activity.startActivity(intent);
}
@Override
public void startDetailActivity(String telephoneNumber) {
if (TextUtils.isEmpty(telephoneNumber)) {
throw new IllegalArgumentException("telephoneNumber is null.");
}
Intent intent = new Intent(this.context, (Class<?>) NewShopDetailActivity.class);
intent.putExtra(SuperNumberConstants.COLUMN_TELNUM, telephoneNumber);
intent.addFlags(268435456);
this.context.startActivity(intent);
}
@Override
public void startTagActivity(RecognitionTelephone recognitionTelephone) {
}
@Override
public void setNetworkAccess(boolean flag) {
NetUtils.setNetworkAccess(this.context, flag);
}
@Override
public String getAreaCodeByCityName(String cityName) {
if (ApplicationMap.getInstance().cityList == null || ApplicationMap.getInstance().cityList.size() < 1) {
ApplicationMap.getInstance().setCityJsonStr(FileUtil.readCityJsonStr());
}
for (City city : ApplicationMap.getInstance().cityList) {
if (city != null && !TextUtils.isEmpty(city.getName()) && city.getName().equals(cityName)) {
return "0" + city.getAreaCode();
}
}
return null;
}
@Override
public String getEnterCentreUrl(String shopId, String entry) {
String url = TextUtils.isEmpty(entry) ? "https://mp.dianhua.cn/index.php?".concat("entry=100000") : "https://mp.dianhua.cn/index.php?".concat("entry=").concat(entry);
if (!TextUtils.isEmpty(Constant.API_KEY)) {
url = url.concat("&apikey=").concat(Constant.API_KEY);
}
if (!TextUtils.isEmpty(shopId)) {
return url.concat("&shop_id=").concat(shopId);
}
return url;
}
@Override
public void updateOfflineFile() {
new Thread(new Runnable() {
@Override
public void run() {
if (NetUtils.isWifiDataEnable(YellowPageApiImpl.this.context)) {
PkgDecoderApi mPkgDecoderApi = YuloreApiFactory.createFileDecoderApi(YellowPageApiImpl.this.context);
OfflinePkgInfos pkgInfos = mPkgDecoderApi.newCheckPkgUpdate(YellowPageApiImpl.this.context);
if (pkgInfos != null) {
YuloreApiFactory.createFileDecoderApi(YellowPageApiImpl.this.context).newDownloadPkg(YellowPageApiImpl.this.context, pkgInfos);
return;
}
return;
}
Toast.makeText(YellowPageApiImpl.this.context, "建议在wifi情况下重试", 0).show();
}
}).start();
}
@Override
public SearchEntity getCategoryList(int categoryId) {
try {
this.merchants = LogicBizFactory.createSearchBiz(this.context).queryMerchants(null, "cat_id=" + categoryId, 0, 0, 20, 0.0d, 0.0d, true, Constant.APP_DB_PATH);
Logger.d(TAG, this.merchants.toString());
} catch (SocketTimeoutException e) {
e.printStackTrace();
} catch (ClientProtocolException e2) {
e2.printStackTrace();
} catch (IOException e3) {
e3.printStackTrace();
} catch (JSONException e4) {
e4.printStackTrace();
}
return this.merchants;
}
@Override
public List<Category> requestHomeCategory() {
HomeEntity homeEntity = requestHomeEntityData();
if (homeEntity != null && homeEntity.allCatList != null) {
List<Category> myCatList = new ArrayList<>();
int size = homeEntity.allCatList.size();
for (int i = 0; i < size; i++) {
int hot = homeEntity.allCatList.get(i).getHot();
if (hot == 1) {
myCatList.add(homeEntity.allCatList.get(i));
}
}
Log.d(TAG, "HomeEntity:myCatlist:" + myCatList.toString());
return myCatList;
}
return null;
}
@Override
public SearchEntity requestSerchEntity(int cat_id) {
try {
SearchEntity entity = LogicBizFactory.createSearchBiz(this.context).queryMerchants(null, "cat_id=" + cat_id, 2, 0, 100, 0.0d, 0.0d, true, Constant.APP_DB_PATH);
return entity;
} catch (SocketTimeoutException e) {
e.printStackTrace();
return null;
} catch (ClientProtocolException e2) {
e2.printStackTrace();
return null;
} catch (IOException e3) {
e3.printStackTrace();
return null;
} catch (JSONException e4) {
e4.printStackTrace();
return null;
}
}
}