BCPay { public static String initWechatPay(Context context, String wechatAppID) { String errMsg = null; if (context == null) { errMsg = "Error: initWechatPay里，context参数不能为null."; Log.e(TAG, errMsg); return errMsg; } if (wechatAppID == null || wechatAppID.length() == 0) { errMsg = "Error: initWechatPay里，wx_appid必须为合法的微信AppID."; Log.e(TAG, errMsg); return errMsg; } wxAPI = WXAPIFactory.createWXAPI(context, null); BCCache.getInstance().wxAppId = wechatAppID; try { if (isWXPaySupported()) { wxAPI.registerApp(wechatAppID); } else { errMsg = "Error: 安装的微信版本不支持支付."; Log.e(TAG, errMsg); } } catch (Exception ignored) { errMsg = "Error: 无法注册微信 " + wechatAppID + ". Exception: " + ignored.getMessage(); Log.e(TAG, errMsg); } return errMsg; } private  BCPay(); synchronized static BCPay getInstance(Context context); static String initWechatPay(Context context, String wechatAppID); static void clear(); static void detachWechat(); static void detachBaiduPay(); static boolean isWXPaySupported(); static boolean isWXAppInstalledAndSupported(); void reqPaymentAsync(final PayParams payParam, final BCCallback callback); void reqWXPaymentAsync(final String billTitle, final Integer billTotalFee,
                                  final String billNum,
                                  final Map<String, String> optional, final BCCallback callback); void reqAliPaymentAsync(final String billTitle, final Integer billTotalFee,
                                   final String billNum,
                                   final Map<String, String> optional,
                                   final BCCallback callback); void reqUnionPaymentAsync(final String billTitle, final Integer billTotalFee,
                                     final String billNum,
                                     final Map<String, String> optional,
                                     final BCCallback callback); void reqBaiduPaymentAsync(final String billTitle, final Integer billTotalFee,
                                     final String billNum,
                                     final Map<String, String> optional,
                                     final BCCallback callback); @Deprecated void reqAliInlineQRCodeAsync(final String billTitle, final Integer billTotalFee,
                                        final String billNum, final Map<String, String> optional,
                                        final String returnUrl,
                                        final String qrPayMode,
                                        final BCCallback callback); void reqBCNativeAsync(final String billTitle, final Integer billTotalFee,
                                 final String billNum, final Map<String, String> optional,
                                 final Boolean genQRCode, final Integer qrCodeWidth,
                                 final BCCallback callback); void prefund(final RefundParams params, final BCCallback callback); void sendSmsCode(final String phone, final BCCallback callback); void subscribe(final BCSubscription params, final String smsId, final String smsCode,
                          final String couponCode, final BCCallback callback); void cancelSubscription(final String sid, final BCCallback callback);  }
@Test public void testInitWechatPay() throws Exception { Object[][] test = new Object[][] { new Object[]{null, null}, new Object[]{activity, null} }; for (Object[] objects : test) { Assert.assertTrue( BCPay.initWechatPay( (Activity) objects[0], (String) objects[1]) .startsWith("Error")); } BCPay.detachWechat(); }