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 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| public class Baichuan {
public static void showDetailPage(Activity activity, String id, String pid, CallbackContext callbackContext) { AlibcBasePage alibcBasePage = new AlibcDetailPage(id); AlibcTaokeParams alibcTaokeParams = new AlibcTaokeParams(pid, "", ""); if (!alibcTaokeParams.isValidPid()) { callbackContext.error("pid无效"); return; } showPage(activity, alibcBasePage, alibcTaokeParams, callbackContext); }
public static void showDetailPageWithUrl(Activity activity, String url, CallbackContext callbackContext) { AlibcBasePage alibcBasePage = new AlibcPage(url); showPage(activity, alibcBasePage, null, callbackContext); }
private static void showPage(Activity activity, AlibcBasePage alibcBasePage, AlibcTaokeParams alibcTaokeParams, final CallbackContext callbackContext) {
AlibcShowParams alibcShowParams = new AlibcShowParams(OpenType.Native, false);
HashMap<String, String> exParams = new HashMap<>(); exParams.put(AlibcConstants.ISV_CODE, "appisvcode");
AlibcTrade.show(activity, alibcBasePage, alibcShowParams, alibcTaokeParams, exParams, new AlibcTradeCallback() {
@Override public void onFailure(int i, String s) { callbackContext.error("导航失败:" + s); }
@Override public void onTradeSuccess(TradeResult tradeResult) { switch (tradeResult.resultType) { case TYPEPAY: JSONObject jsonObject = new JSONObject(); try { jsonObject.put("successArr", tradeResult.payResult.paySuccessOrders); jsonObject.put("failureArr", tradeResult.payResult.payFailedOrders); callbackContext.success(jsonObject); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("json转换异常:" + e.getMessage()); } break; case TYPECART: callbackContext.success("您已经将商品添加到购物车了,赶快去购买吧"); break; default: callbackContext.error("未知的结果类型"); break; } } }); }
public static void login(final Activity context) {
final AlibcLogin alibcLogin = AlibcLogin.getInstance();
alibcLogin.showLogin(context, new AlibcLoginCallback() {
@Override public void onSuccess() { Toast.makeText(context, "登录成功 ", Toast.LENGTH_LONG).show(); Log.i("Baichuan", "获取淘宝用户信息: " + AlibcLogin.getInstance().getSession());
}
@Override public void onFailure(int code, String msg) { Toast.makeText(context, "登录失败 ", Toast.LENGTH_LONG).show(); } }); } }
|