1.导入sdk官方可下载
2.导入混淆
-keep class com.hyphenate.** {*;}
-dontwarn com.hyphenate.**
-libraryjars libs/alipaySDK-20170922.jar
-keep class com.alipay.android.app.IAlixPay{*;}
-keep class com.alipay.android.app.IAlixPay$Stub{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback$Stub{*;}
-keep class com.alipay.sdk.app.PayTask{ public *;}
-keep class com.alipay.sdk.app.AuthTask{ public *;}
将请求返回的数据传入方法
private void pay(String data){
final String orderInfo=data;//订单信息
Runnable payRunnable=new Runnable(){
@Override
public void run(){
PayTask alipay=new PayTask((Activity)context);
String result=alipay.pay(orderInfo,true);
Message msg=new Message();
msg.what=1000;
msg.obj=result;
mHandler.sendMessage(msg);
}
};
//必须异步调用
Thread payThread=new Thread(payRunnable);
payThread.start();
}
//new一个handler内部类
private Handler mHandler=new Handler(){
@Override
public void handleMessage(Message msg){
super.handleMessage(msg);
if(msg.what==1000){
String result=(String)msg.obj;
if(result.contains("9000")){
Toast.makeText(context,"支付成功",Toast.LENGTH_SHORT).show();
SharedPreUtils.put(context,"AliPay",2);
((VIPActivity)context).finish();
}else{
if(result.contains("6001")){
Toast.makeText(context,"用户取消",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context,"支付失败",Toast.LENGTH_SHORT).show();
}
}
Logger.i("TestActivity",result);
}
}
};