Giter Site home page Giter Site logo

react-native-unionpay's Introduction

react-native银联插件

银联官方

安装

npm i -S react-native-unionpay
react-native link react-native-unionpay

IOS 配置

  • 在工程info.plist设置中添加一个URL Types回调协议(在UPPayDemo工程中使用“UPPayDemo”作为协议),用于在支付完成后返回商户客户端。
  • http请求设置: 在Xcode7.0之后的版本中进行http请求时,需要在工程对应的plist文件中添加NSAppTransportSecurity Dictionary 并同时设置里面NSAllowsArbitraryLoads 属性值为 YES
  • 添加协议白名单: 在Xcode7.0之后的版本中进行开发,需要在工程对应的plist文件中,添加LSApplicationQueriesSchemes Array并加入uppaysdk、uppaywallet、uppayx1、uppayx2、uppayx3五个item
  • AppDelegate.m 的 下面 @end 前面添加下面代码
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}

调用插件

import * as Unionpay from 'react-native-unionpay'
/*
* tn 交易流水号,商户后台向银联后台提交订单信息后,由银联后台生成并下发给商户后台的交易凭证;
* mode 接入模式,标识商户以何种方式调用支付控件,该参数提供以下两个可选值:"00"代表接入生产环境(正式版本需要);"01"代表接入开发测试环境(测试版本需要);
*/
Unionpay.startPay(tn, mode)
.then(res => {
	console.log(res, 'see payment res');
})
catch(err => {
	//检查返回的对象有code属性
	if(typeof err == 'object' && err.code) {
		//code 当失败的时候值有:fail,cancel
	}
	console.warn(err, 'payment failed ');
})

测试账号

以下是测试用卡号、手机号等信息(此类信息仅供测试使用,不会发生真实交易) 银联官方

招商银行借记卡:6226090000000048  
手机号:18100000000  
密码:111101
短信验证码:123456(先点获取验证码之后再输入)  
证件类型:01身份证  
证件号:510265790128303  
姓名:张三
华夏银行贷记卡:6226388000000095
手机号:18100000000
CVN2:248
有效期:1219
短信验证码:123456(先点获取验证码之后再输入)
证件类型:01身份证
证件号:510265790128303
姓名:张三

react-native-unionpay's People

Contributors

magicwing avatar twohouses avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-unionpay's Issues

unionpay 和 支付宝冲突

所有的外链APP回掉都会走 RCTOpenURLNotification 这个通知,而在CFBundleURLTypes 你无法判断CFBundleURLName 具体是在 CFBundleURLTypes 里第几个位置 建议改成支付宝的判断方法 做如下修改
NSArray *urlTypes = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleURLTypes"];
for (NSDictionary *item in urlTypes) {
NSString *name = item[@"CFBundleURLName"];
if ([name isEqualToString:@"upay"]) {
NSArray *schemes = item[@"CFBundleURLSchemes"];
if (schemes.count > 0)
{
self.schemeStr = schemes[0];
break;
}
}
}
否则

NSArray *urlTypes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"];
NSArray *urlSchemes = [[urlTypes objectAtIndex:3] objectForKey:@"CFBundleURLSchemes"];
if(urlSchemes.count > 0) {
    self.schemeStr = [urlSchemes firstObject];
}

这个方法无论哪个在firstObject 你都会取到 CFBundleURLSchemes 它不一定是unionpay 而 canOpen = [aURLString hasPrefix:scheme]; 返回YES
[body setObject:code forKey:@"code"];
[self sendEventWithName:@"UnionPay_Resp" body: body];
这里可能会导致崩溃

当然 你也可以把 他放进 if(data != nil) { } 这样更安全

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.