标签:
步骤
1、导入Jar包----将HeepayPlugin.jar,HftJuhePay.jar 包放入工程指定的libs目录。
2、配置清单文件----添加权限,添加activity等组件3、编码接入----支付参数传递,支付结果回调4、其他请参考说明文档
演示代码
public class MainActivity extends Activity {
private static String TAG = "bqt";private Context mContext;private RadioGroup mRgPayType;//支付方式private RadioButton mRBtnWeChat;//微信private RadioButton mRBtnAlipay;//支付宝private ClearEditText mEtPayAmount;//金额private Button mBtnPay;//支付private String mStrPayMode = "1";// 支付方式:微信=1,支付宝=2protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);mContext = this;setContentView(R.layout.activity_main);findViews();setLitener();}private void findViews() {mRgPayType = (RadioGroup) findViewById(R.id.rg_pay_way);mRBtnWeChat = (RadioButton) findViewById(R.id.rb_wechat_pay);mRBtnAlipay = (RadioButton) findViewById(R.id.rb_alipay);mEtPayAmount = (ClearEditText) findViewById(R.id.activity_main_et_pay_amount);mBtnPay = (Button) findViewById(R.id.activity_main_btn_pay);}private void setLitener() {mRgPayType.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {if (checkedId == mRBtnWeChat.getId()) mStrPayMode = "1";if (checkedId == mRBtnAlipay.getId()) mStrPayMode = "2";}});mBtnPay.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {if (TextUtils.isEmpty(mEtPayAmount.getText().toString().trim())) {Toast.makeText(mContext, "请输入金额", Toast.LENGTH_SHORT).show();return;}HashMap<String, String> params = new HashMap<String, String>();params.put("pay_mode", mStrPayMode); // 支付方式:微信=1,支付宝=2params.put("order_id", getAppKey(mContext) + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())); // 订单号params.put("pay_amt", mEtPayAmount.getText().toString().trim()); // 支付金额params.put("notify_url", "www.baidu.com"); // 通知地址params.put("goods_name", "虚拟测试产品"); // 商品名称params.put("goods_note", "虚拟测试产品0.01元"); // 商品价格信息,可为空params.put("extends_info", "无"); // 标记params.put("goods_num", "1"); // 商品数量HftJuhePay.getInstance().pay(mContext, params, new OnPayFinishedListener() {@Overridepublic void onPaySuccess(Map params) {printLog(params, "支付成功---");}@Overridepublic void onPayFail(Map params, int errorInt) {printLog(params, "支付失败---");}@Overridepublic void onPayCancel(Map params) {printLog(params, "支付取消---");}@Overridepublic void onPayProcess(Map params) {printLog(params, "支付处理中---");}});}});}private void printLog(Map params, String toast) {Toast.makeText(mContext, toast + params, Toast.LENGTH_LONG).show();Log.i(TAG, "params=" + params.toString());//goods_name=虚拟测试产品, total_amt=0.5, extends_info=无, goods_num=1,//order_id=S4LjqtXxozaVYDqSDMh1MliO20160317183136, goods_note=虚拟测试产品0.01元String mStrOrderId = ((Map<String, String>) params).get("order_id");//订单号String mStrTotalAmount = ((Map<String, String>) params).get("total_amt");//支付总金额String mStrGoodsName = ((Map<String, String>) params).get("goods_name");//商品名称String mStrGoodsNote = ((Map<String, String>) params).get("goods_note");//商品说明String mStrGoodsNum = ((Map<String, String>) params).get("goods_num");//商品数量String mStrExtendsInfo = ((Map<String, String>) params).get("extends_info");//扩展信息}/** 获取App_Key */public static String getAppKey(Context context) {return getStringMetaData(context, "HFT_APP_KEY");}private static String getStringMetaData(Context context, String key) {Bundle metaData = getMetaData(context);String strVal = metaData != null ? metaData.getString(key) : null;return strVal != null ? strVal : "";}private static Bundle getMetaData(Context context) {if (context == null) return null;PackageManager pm = context.getPackageManager();try {ApplicationInfo appInfo = pm.getApplicationInfo(context.getPackageName(), 128);if (appInfo != null) return appInfo.metaData;} catch (PackageManager.NameNotFoundException e) {e.printStackTrace();}return null;}}
标签:
原文地址:http://www.cnblogs.com/baiqiantao/p/5288825.html