/rn-walipay

安卓 ios 的支付宝支付 挂载在rn上,支持支付宝版本1.0,2.0

Primary LanguageC

rn-walipay

react-native 支付宝手机支付模块

安装

##iOS

  1. npm install https://github.com/mingkang1993/rn-walipay.git --save
  2. 去官方下ios android 包,放入 android/libs下面
  3. 在XCode中右击项目的 Libraries 文件夹 ➜ Add Files to
  4. 进入 node_modulesrn-alipayios ➜ 选择 RNAlipay.xcodeproj
  5. 展开RNAlipay.xcodeprojProducts➜ 添加 libRNAlipay.aBuild Phases -> Link Binary With Libraries
  6. Build Phases选项卡的Link Binary With Libraries中,点击“+”号增加以下依赖:
  7. RNAlipay.xcodeprojAlipaySDK.frameworklibssl.alibcrypto.a文件拖入复制到项目文件夹下:
  8. 编译运行

##Android

  • npm install https://github.com/mingkang1993/rn-walipay.git --save
// file: android/settings.gradle
...
include ':rn-alipay'  // <- add
project(':rn-alipay').projectDir = new File(settingsDir, '../node_modules/rn-alipay/android')  // <- add
// file: android/app/build.gradle
...
dependencies {
		...
		compile project(':rn-alipay')  // <- add
}
  • 注册模块
  • 对于 react-native 版本低于 0.19.0 (use cat ./node_modules/react-native/package.json | grep version)
// file: MainActivity.java
import com.alipay.RNAlipayPackage;  // <- import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {

  ...

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mReactRootView = new ReactRootView(this);

    mReactInstanceManager = ReactInstanceManager.builder()
      .setApplication(getApplication())
      .setBundleAssetName("index.android.bundle")
      .setJSMainModuleName("index.android")
      .addPackage(new MainReactPackage())
      .addPackage(new RNAlipayPackage(this))      // <- add package
      .setUseDeveloperSupport(BuildConfig.DEBUG)
      .setInitialLifecycleState(LifecycleState.RESUMED)
      .build();

    mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null);

    setContentView(mReactRootView);
  }

  ...

}
  • 对于 react-native 0.19.0及以上版本
// file: MainActivity.java
	...
import com.alipay.RNAlipayPackage;//<- import package

public class MainActivity extends ReactActivity {

   /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(), //<- Add comma
            new RNAlipayPackage(this) //<- Add package
        );
    }
...
}

##使用说明

  1. 导入模块
const Alipay = require('rn-walipay');
  1. 基本使用
const data = {
    payInfo,
    appSchemeIOS: 'testapp20', //应用注册scheme,Info.plist定义URL types
};
Alipay.pay(data).then((msg) => {
    console.log(msg);
}, (e) => {
    console.log(e);
});

##参考支付宝文档