React-Native调用支付宝,微信

  • https://www.pingxx.com/docs/downloads
  • Ping++ 是为移动端应用以及 PC 网页量身打造的下一代支付系统,通过一个 SDK 便可以同时支持移动端以及 PC 端网页的多种主流支付渠道,你只需要一次接入即可完成多个渠道的接入。 Ping++ SDK 包括 Client SDK 和 Server SDK 两部分,支持主流的七种后端开发语言,适配了 Android,iOS 和 HTML5 三种移动端平台以及 PC 端网页。

    支持以下渠道支付

    支付宝 (alipay)

    微信支付 (wx)

    银联支付(upacp)

    百付宝Wap (bfb_wap)

    QQ钱包 (qpay)


  • /**
     * Sample React Native App
     * https://github.com/facebook/react-native
     * @flow
     */
    
    import React, { Component } from 'react';
    import {
      AppRegistry,
      StyleSheet,
      Text,
      View,
      TouchableOpacity
    } from 'react-native';
    
    var NetUtil = require('./netutil.js');
    var Pingpp = require('pingpp-react-native');
    
    export default class PingppDemoApp extends Component {
      setDebugModel(enabled) {
        Pingpp.setDebugModel(enabled);
      };
    
      pay(channel) {
        NetUtil.postJson(
          "http://218.244.151.190/demo/charge",
          {amount: 1, channel: channel, order_no: new Date().getTime()},
          function(object) {
            Pingpp.createPayment(
              {
                "object":object,
                "scheme":"pingppdemoapp"
              }, function(res, error) {
                alert(res);
                console.log(error);
                alert(JSON.stringify(error));
              }
            );
          }
        );
      }
    
      render() {
        return (
          <View style={styles.container}>
            <TouchableOpacity onPress = {()=>{this.pay("alipay")}}>
              <Text style={styles.welcome}>支付宝</Text>
            </TouchableOpacity>
            <TouchableOpacity onPress={()=>{this.pay("wx")}}>
              <Text style={styles.welcome}>微信</Text>
            </TouchableOpacity>
            <TouchableOpacity onPress={()=>{this.pay("upacp")}}>
              <Text style={styles.welcome}>银联</Text>
            </TouchableOpacity>
            <TouchableOpacity onPress={()=>{this.pay("qpay")}}>
              <Text style={styles.welcome}>QQ钱包</Text>
            </TouchableOpacity>
            <TouchableOpacity onPress={()=>{this.setDebugModel(true)}}>
              <Text style={styles.welcome}>开启调试</Text>
            </TouchableOpacity>
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
      },
      welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
      },
      instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
      },
    });