TPUnionPay 1.0.1

TPUnionPay 1.0.1

TestsTested
LangLanguage Objective C++Objective C++
License MIT
ReleasedLast Release May 2017

Maintained by kingdomrain.



  • By
  • kingdomrain

Release Notes

1.0.0

基于SDK 3.3.6版本

1.0.1

更新时间:2017年5月21号 增加mode字段,当前视图控制器获取机制修改

Usage

var union=new UnionPay();
union.tn="111111";    //tn信息,服务端生成
union.mode="00";       //模式 "00" 正式环境 "01"
union.success=function(data){
	window.alert('支付成功');
}
union.error=function(data){
  alert('支付失败');
}
union.pay();

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

1.首先,在AppDelegate文件中引入头文件 TPUnionPay/UPPaymentControl.h。
支付控件结果处理函数handlePaymentResult: completeBlock:需要在工程AppDelegate文件的application: openURL: options: 方法中进行调用。添加如下代码:

    //通联支付
[[UPPaymentControl defaultControl] handlePaymentResult:url completeBlock:^(NSString *code, NSDictionary *data) {
 
 //结果code为成功时,先校验签名,校验成功后做后续处理
 if([code isEqualToString:@"success"]) {
 
 [[NSNotificationCenter defaultCenter] postNotificationName:@"UnionPaySuccess" object:nil];
 
 
 //判断签名数据是否存在
 if(data == nil){
 //如果没有签名数据,建议商户app后台查询交易结果
 return;
 }
 
 //数据从NSDictionary转换为NSString
 NSData *signData = [NSJSONSerialization dataWithJSONObject:data
                                                    options:0
                                                      error:nil];
 NSString *sign = [[NSString alloc] initWithData:signData encoding:NSUTF8StringEncoding];
 

 //验签证书同后台验签证书
 //此处的verify,商户需送去商户后台做验签
 //            if([self verify:sign]) {
 //                //支付成功且验签成功,展示支付成功提示
 //            }
 //            else {
 //                //验签失败,交易结果数据被篡改,商户app后台查询交易结果
 //            }
 }
 else if([code isEqualToString:@"fail"]) {
 //交易失败
 [[NSNotificationCenter defaultCenter] postNotificationName:@"UnionPayError" object:nil];
 }
 else if([code isEqualToString:@"cancel"]) {
 //交易取消
 [[NSNotificationCenter defaultCenter] postNotificationName:@"UnionPayError" object:nil];
 }
 }];

2.工程配置
2.1在工程info.plist设置中添加一个URL Types回调协议(在UPPayDemo工程中使用“UPPayDemo”作为协议),用于在支付完成后返回商户客户端。 2.2在Xcode7.0之后的版本中进行开发,需要在工程对应的plist文件中,添加LSApplicationQueriesSchemes Array并加入uppaysdk、uppaywallet、uppayx1、uppayx2、uppayx3五个item,具体设置可参考以下截图:

3.注册JS扩展
在tinyPlus.plist中注册JS扩展

Installation

TPUnionPay is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "TPUnionPay"

tips

官方帮助文档地址
https://open.unionpay.com/ajweb/product/detail?id=3

Author

kingdomrain, [email protected]

License

TPUnionPay is available under the MIT license. See the LICENSE file for more info.