1.申请百川无线应用
2.开通业务产品的使用权限
- 初级电商
3.获取安全图片 - 需要上传apk包,主要是获取包名以及签名,生成安全图片,所以这个安全图片与你上传的签名有关系,如果签名文件变了,那么安全图片要重新生成。
- 一定要使用gradle3.0以下的编译环境的包,不然会提示“上传失败”
buildscript {
repositories {
maven {
url "http://repo.baichuan-android.taobao.com/content/groups/BaichuanRepositories/"
}
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'//使用3.0一下,估计后期阿里会升级吧,目前要这样才行,不然一直上传失败
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
url "http://repo.baichuan-android.taobao.com/content/groups/BaichuanRepositories/"
}
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app内的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
defaultConfig {
applicationId "com.stockchart.demo.liuliang"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
signingConfigs {
debug {
keyAlias 'alias'
keyPassword 'a123456'
storeFile file('./test.jks')
storePassword 'a123456'
}
release {
keyAlias 'alias'
keyPassword 'a123456'
storeFile file('./test.jks')
storePassword 'a123456'
}
}
buildToolsVersion '27.0.3'
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
//fastjson
compile 'com.alibaba:fastjson:1.2.9'
//支付
compile 'com.alibaba.alipay:alipaySingle:20160825@jar'
//登陆
compile 'com.ali.auth.sdk:alibabauth_core:1.1.4@jar'
compile 'com.ali.auth.sdk:alibabauth_ui:1.1.4@aar'
compile 'com.ali.auth.sdk:alibabauth_ext:1.1.4@jar'
//【可选】仅供特殊合作伙伴使用
compile 'com.ali.auth.sdk:alibabauth_accountlink:1.1.4@jar'
//安全基础
compile 'com.taobao.android:securityguardaar3:5.1.81@aar'
//【可选】安全高级,如使用了发放红包、优惠券高级功能,则必须引入
compile 'com.taobao.android:securitybodyaar3:5.1.25@aar'
//Mtop网关
compile 'com.taobao.android:mtopsdk_allinone_open:1.2.2.4@jar'
//applink
compile 'com.alibaba.sdk.android:alibc_link_partner:1.1.0.0'
//UT
compile 'com.taobao.android:utdid4all:1.1.5.3_proguard@jar'
compile 'com.alibaba.mtl:app-monitor-sdk:2.5.1.3_for_bc_proguard@jar'
//电商SDK
compile 'com.alibaba.sdk.android:alibc_trade_common:3.1.1.99'
compile 'com.alibaba.sdk.android:alibc_trade_biz:3.1.1.99'
compile 'com.alibaba.sdk.android:alibc_trade_sdk:3.1.1.99'
}
修改AndroidManifest.xml
- 添加权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
- application 添加属性
tools:replace="android:allowBackup"
在Application onCreate()中异步初始化
//电商SDK初始化
AlibcTradeSDK.asyncInit(this, new AlibcTradeInitCallback() {
@Override
public void onSuccess() {
Toast.makeText(AliSdkApplication.this, "初始化成功", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(int code, String msg) {
Toast.makeText(AliSdkApplication.this, "初始化失败,错误码="+code+" / 错误消息="+msg, Toast.LENGTH_SHORT).show();
}
});
工具类
public class BaiChuanUtil {
private final static String H5 = "H5";
private final static String TAOBAO = "taobao";
private final static String TMALL = "tmall";
private final static String AUTO = "auto";
private static void showDetailPage(Activity activity, String id, String type) {
AlibcShowParams alibcShowParams;
switch (type) {
case H5:
alibcShowParams = new AlibcShowParams(OpenType.H5, false);
break;
case TAOBAO:
alibcShowParams = new AlibcShowParams(OpenType.Native, false);
alibcShowParams.setClientType("taobao_scheme");
break;
case TMALL:
alibcShowParams = new AlibcShowParams(OpenType.Native, false);
alibcShowParams.setClientType("tmall_scheme");
break;
case AUTO:
alibcShowParams = new AlibcShowParams(OpenType.Auto, false);
break;
default:
alibcShowParams = new AlibcShowParams(OpenType.Auto, false);
break;
}
AlibcBasePage alibcBasePage = new AlibcDetailPage(id);
HashMap<String, String> exParams = new HashMap<>();
// 固定写法
exParams.put(AlibcConstants.ISV_CODE, "appisvcode");
// 若非淘客taokeParams设置为null即可 mm_memberId_siteId_adzoneId
// pid:广告位id
AlibcTaokeParams alibcTaokeParams = new AlibcTaokeParams("mm_123352308_40788301_344524398", "mm_123352308_40788301_344524398", null);
AlibcTrade.show(activity, alibcBasePage, alibcShowParams, alibcTaokeParams, exParams, new AlibcTradeCallback() {
@Override
public void onTradeSuccess(AlibcTradeResult alibcTradeResult) {
}
@Override
public void onFailure(int i, String s) {
// Toast.makeText(App.getInstance(), "初始化失败,错误码=" + i + " / 错误消息=" + s, Toast.LENGTH_SHORT).show();
}
});
}
/**
* 跳淘宝详情
*/
public static void showTaobaoDetail(Activity activity, String id) {
if (Tools.isApplicationAvilible(activity, "com.taobao.taobao")) {
showDetailPage(activity, id, TAOBAO);
} else {
showDetailPage(activity, id, AUTO);
}
}
/**
* 跳天猫详情
*/
public static void showTmallDetail(Activity activity, String id) {
if (Tools.isApplicationAvilible(activity, "com.tmall.wireless")) {
showDetailPage(activity, id, TMALL);
} else {
showDetailPage(activity, id, AUTO);
}
}
}
以上是Android配置部分
接下来是网站上需要设置的
首先找到控制台
创建应用
重要的是应用包名要写对
获取安全图片,如果你上传一直失败,请把使用gradle3.0以下的编译环境的包,比如
classpath 'com.android.tools.build:gradle:2.3.3'
下载安全图片放入如图,最好不要改它名字,(我没试过)
开通两项功能
进入淘宝联盟,使用之前的帐号登录
新增app推广
来到联盟首页,随意搜索商品推广
选择之前新建的已经通过审核的app
来到app推广位就可以看到我们要推广的产品了,其中比较重要的是pid
代码中的使用
AlibcTaokeParams alibcTaokeParams = new AlibcTaokeParams(pid, pid, null);
之前我们搜索的商品点进去
在地址栏可以获取到该商品的id
代码中的体现
AlibcBasePage alibcBasePage = new AlibcDetailPage(id);
结束!