• app微信支付的集成步骤



    1.引用地址

    //微信支付
    compile 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+'


    2.注册
        private IWXAPI api;
        api = WXAPIFactory.createWXAPI(this, appid);


    3. 发起请求  (结果是后台返回的)

    PayReq req = new PayReq();
    req.appId = "wxa9f8f372188a6867";
    req.partnerId = "1487600712";
    req.packageValue = "Sign=WXPay";

    req.prepayId = "wx201710032153051e158cdeb50210343037";
    req.nonceStr = "6md852kc4uik1m3bzr4sl3v5lr1ohh4d";
    req.timeStamp = "1507038785";
    req.sign = "0D684FF4D47E0E265E33FD67B3AE4CA7";
    api.sendReq(req);

    4.回调结果:

    1.要在项目包名下新建wxapi包,
    2.WXPayEntryActivity必须是这个类,实现这个接口IWXAPIEventHandler

    3. 在清单文件中注册
    <activity
    android:name=".wxapi.WXPayEntryActivity"
    android:exported="true"
    android:launchMode="singleTop"/>

    //回调的页面
    public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pay_result);

    api = WXAPIFactory.createWXAPI(this,appid);
    api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
    api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {

    if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("提示");
    builder.setMessage(getString(R.string.pay_result_callback_msg, String.valueOf(resp.errCode)));
    builder.show();
    }
    }
    }

  • 相关阅读:
    Linux 下curl模拟Http 的get or post请求
    ShopNC学习笔记(转)
    (转) shopnc数据库操作
    Mysql开发规范
    长连接、短连接、长轮询和WebSocket
    一个支付宝没有安装app时看不到web网页,无法支付的问题
    MVVM设计模式
    c中的scanf和printf
    import和class关键字的区别
    oc中的注释
  • 原文地址:https://www.cnblogs.com/yy2012/p/7624769.html
Copyright © 2020-2023  润新知