
6. 如何捕获回调接口CarrotPayCallbackMethodInterceptor类实现返回的参数
public class CarrotPayCallbackMethodInterceptor implements InvocationHandler { CarrotPaySdkFinal csf; public CarrotPayCallbackMethodInterceptor (CarrotPaySdkFinal paytype){ csf = paytype; } @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // TODO Auto-generated method stub switch (csf) { case CMCC_PAY: //在这里获得回调函数返回的参数,通过自定义carrotSdkHelper发送给callback处理返回结果 for(int j = 0; j < args.length;j++){ if(args[j].getClass().getName().equalsIgnoreCase("java.lang.Integer")){ Integer result = (Integer)args[j]; switch (result) { case 1: Message msg_cmcc_success = new Message(); msg_cmcc_success.what = CarrotPaySDK.CARROT_PAY_SUCCESS; CarrotPaySDK.carrotSdkHleper.cmcc_PayendHandler.sendMessage(msg_cmcc_success); break; case 2: Message msg_cmcc_faild = new Message(); msg_cmcc_faild.what = CarrotPaySDK.CARROT_PAY_FAILD; CarrotPaySDK.carrotSdkHleper.cmcc_PayendHandler.sendMessage(msg_cmcc_faild); break; default: Message msg_cmcc_faild2 = new Message(); msg_cmcc_faild2.what = CarrotPaySDK.CARROT_PAY_FAILD; CarrotPaySDK.carrotSdkHleper.cmcc_PayendHandler.sendMessage(msg_cmcc_faild2); break; } } } break; case OTHER_PAY: Log.e("___________OTHER_______________", "____________________"+method.getName()); for(int j = 0; j < args.length;j++){ Log.e("___________OTHER_______________"+args[j].getClass().getName(), "____________________"+args[j].toString()); } Log.e("___________OTHER_______________", "______333333______________"); break; default: break; } return null; } }
7. (1)回调类的介绍
public interface CarrotPayCallBack { public void onPayEnd(int isSuccess); }

(2)创建一个新的CarrotPayCallBack并将其传递给4步方法
new CarrotPayCallBack() { @Override public void onPayEnd(int isSuccess) { // TODO Auto-generated method stub switch (isSuccess) { case CarrotPaySDK.CARROT_PAY_SUCCESS: Toast.makeText(getApplicationContext(), "支付成功", Toast.LENGTH_SHORT).show(); break; case CarrotPaySDK.CARROT_PAY_CANCEL: Toast.makeText(getApplicationContext(), "支付取消", Toast.LENGTH_SHORT).show(); break; case CarrotPaySDK.CARROT_PAY_FAILD: Toast.makeText(getApplicationContext(), "支付失败", Toast.LENGTH_SHORT).show(); break; case CarrotPaySDK.CARROT_PAY_UNKNOW: Toast.makeText(getApplicationContext(), "未知错误", Toast.LENGTH_SHORT).show(); break; default: break; } } }
8. 该代码已提交到github,如有必要,请移动
9. 我已经在CSDN上发送了此邮件
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-277409-2.html
一样的东西实体店卖100