项目主页: https://github.com/shopex/prism-android/
实现shopex Prism 的Android版SDK供第三方使用
Android 1.6+ JDK6以上版本
String redirectUrl = "http://buwb2lii.com/oauth-adapter?action=callback";
String clientId = "buwb2lii";
PrismOauth oauth = new PrismOauth(context,clientId,redirectUrl);
oauth.authorize(new PrismOauthListener() {
@Override
public void onSuccess(OAuth data) {
System.out.println("登录成功:"+data.getAccess_token());
UIUtils.showAlert(MainActivity.this, "成功","登录成功:"+data.getAccess_token());
//用户需将OAuth对象保存本地,以后再次发送请求的时候将access_token带入头部
}
@Override
public void onFaliure(int code, String result) {
UIUtils.showAlert(MainActivity.this, "失败",result+":"+code);
}
@Override
public void onException(PrismException exception) {
// TODO Auto-generated method stub
}
@Override
public void onCancel() {
UIUtils.showAlert(MainActivity.this, "失败","用户取消");
}
});
//context 为上下文环境 OAuth 为提供OAuth认证后返回的数据,将OAuth妥善保管在本地,如果没有OAuth 请传入null
NetworkClient networkClient = new NetworkClient(context,oAuth);
//等到获得是在setOAuth即可
networkClient.setOAuth(oAuth);
networkClient.get(clientId, clientSecret, url,new ShopExAsynchResponseHandler(){
@Override
public void onSuccess(int status, Header[] headers,
byte[] body) {
// 返回正确结果
super.onSuccess(status, headers, body);
String json = new String(body);
}
@Override
public void onFailure(int status, Header[] headers,
byte[] body, Throwable e) {
// 返回错误信息
super.onFailure(status, headers, body, e);
}
});
/*
* 参数设置
*
/
public class TestReq extends AbstractCommonReq{
public TestReq(String t1,String t2){
add("t1",t1);
add("t2",t2);
}
}
networkClient.post(clientId, clientSecret, url,new TestReq(),new ShopExAsynchResponseHandler(){
@Override
public void onSuccess(int status, Header[] headers,
byte[] body) {
// 返回正确结果
super.onSuccess(status, headers, body);
String json = new String(body);
}
@Override
public void onFailure(int status, Header[] headers,
byte[] body, Throwable e) {
// 返回错误信息
super.onFailure(status, headers, body, e);
}
});