第三方外掛程式-微信支付接入注意問題,第三方外掛程式

來源:互聯網
上載者:User

第三方外掛程式-支付接入注意問題,第三方外掛程式

1、對於訂單的簽名在服務端,因此用戶端相對比較簡單。

2、調用支付介面

<span style="font-family:Comic Sans MS;font-size:14px;"> private void weixinPay() {Map<String, String> mapOrder = getOrderMap();api = WXAPIFactory.createWXAPI(WebPayActivity.this,null);api.registerApp(mapOrder.get("appid"));    PayReq req = new PayReq();req.appId= mapOrder.get("appid");req.partnerId= mapOrder.get("partnerid");req.prepayId= mapOrder.get("prepayid");req.nonceStr= mapOrder.get("noncestr");req.timeStamp= mapOrder.get("timestamp");req.packageValue= mapOrder.get("package");req.sign= mapOrder.get("sign");GammPayFactory.getInstance().setAppid(mapOrder.get("appid"));// 在支付之前,如果應用沒有註冊到,應該先調用IWXMsg.registerApp將應用註冊到api.sendReq(req);}</span>

3、通過api.sendReq(req)返回true表示已經接通,可以啟動支付介面。

注意:使用支付,你的app必須進行正式的簽名,在上註冊包名,簽名。否則返回true,但是沒有反應。

4、支付成功之後回調

在你的包名下建立wxapi包,然後將demo裡面的WXPayEntryActivity類拷貝進來,預設的代碼如下。其中onResp方法是執行結果的回調方法。

<span style="font-family:Comic Sans MS;font-size:14px;">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, Constants.APP_ID);        api.handleIntent(getIntent(), this);    }@Overrideprotected void onNewIntent(Intent intent) {super.onNewIntent(intent);setIntent(intent);        api.handleIntent(intent, this);}@Overridepublic void onReq(BaseReq req) {}@Overridepublic void onResp(BaseResp resp) {Log.d(TAG, "onPayFinish, errCode = " + resp.errCode);if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle(R.string.app_tip);builder.setMessage(getString(R.string.pay_result_callback_msg, String.valueOf(resp.errCode)));builder.show();}}}</span>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.