app微信支付的集成步骤

博观而约取,厚积而薄发。这篇文章主要讲述app微信支付的集成步骤相关的知识,希望能为你提供帮助。

1.引用地址
【app微信支付的集成步骤】 //微信支付
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 = "https://www.songbingjia.com/android/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();
}
}
}






















































    推荐阅读