Commit 68a4164f by lee

u

parents da41cff9 534c3f10
//
// APAuthInfo.h
// AliSDKDemo
//
// Created by alipay on 16-12-12.
// Copyright (c) 2016年 Alipay.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface APayAuthInfo : NSObject
@property(nonatomic, copy)NSString *appID;
@property(nonatomic, copy)NSString *pid;
@property(nonatomic, copy)NSString *redirectUri;
/**
* 初始化AuthInfo
*
* @param appIDStr 应用ID
* @param pidStr 商户ID 可不填
* @param uriStr 授权的应用回调地址 比如:alidemo://auth
*
* @return authinfo实例
*/
- (id)initWithAppID:(NSString *)appIDStr
pid:(NSString *)pidStr
redirectUri:(NSString *)uriStr;
- (NSString *)description;
- (NSString *)wapDescription;
@end
//
// AlipaySDK.h
// AlipaySDK
//
// Created by alipay on 16-12-12.
// Copyright (c) 2016年 Alipay. All rights reserved.
//
////////////////////////////////////////////////////////
///////////////// 支付宝标准版本支付SDK ///////////////////
/////////// version:15.3.3 motify:2017.03.07 ///////////
////////////////////////////////////////////////////////
#import "APayAuthInfo.h"
typedef enum {
ALIPAY_TIDFACTOR_IMEI,
ALIPAY_TIDFACTOR_IMSI,
ALIPAY_TIDFACTOR_TID,
ALIPAY_TIDFACTOR_CLIENTKEY,
ALIPAY_TIDFACTOR_VIMEI,
ALIPAY_TIDFACTOR_VIMSI,
ALIPAY_TIDFACTOR_CLIENTID,
ALIPAY_TIDFACTOR_APDID,
ALIPAY_TIDFACTOR_MAX
} AlipayTidFactor;
typedef void(^CompletionBlock)(NSDictionary *resultDic);
@interface AlipaySDK : NSObject
/**
* 创建支付单例服务
*
* @return 返回单例对象
*/
+ (AlipaySDK *)defaultService;
/**
* 用于设置SDK使用的window,如果没有自行创建window无需设置此接口
*/
@property (nonatomic, weak) UIWindow *targetWindow;
/**
* 支付接口
*
* @param orderStr 订单信息
* @param schemeStr 调用支付的app注册在info.plist中的scheme
* @param compltionBlock 支付结果回调Block,用于wap支付结果回调(非跳转钱包支付)
*/
- (void)payOrder:(NSString *)orderStr
fromScheme:(NSString *)schemeStr
callback:(CompletionBlock)completionBlock;
/**
* 处理钱包或者独立快捷app支付跳回商户app携带的支付结果Url
*
* @param resultUrl 支付结果url
* @param completionBlock 支付结果回调
*/
- (void)processOrderWithPaymentResult:(NSURL *)resultUrl
standbyCallback:(CompletionBlock)completionBlock;
/**
* 获取交易token。
*
* @return 交易token,若无则为空。
*/
- (NSString *)fetchTradeToken;
/**
* 是否已经使用过
*
* @return YES为已经使用过,NO反之
*/
- (BOOL)isLogined;
/**
* 获取当前版本号
*
* @return 当前版本字符串
*/
- (NSString *)currentVersion;
/**
* 获取当前tid相关信息
*
* @return tid相关信息
*/
- (NSString*)queryTidFactor:(AlipayTidFactor)factor;
/**
* 測試所用,realse包无效
*
* @param url 测试环境
*/
- (void)setUrl:(NSString *)url;
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////h5 拦截支付入口///////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
/**
* 从h5链接中获取订单串接口
*
* @param urlStr 拦截的 url string
*
* @return 获取到的url order info
*/
- (NSString*)fetchOrderInfoFromH5PayUrl:(NSString*)urlStr;
/**
* h5链接获取到的订单串支付接口
*
* @param orderStr 订单信息
* @param schemeStr 调用支付的app注册在info.plist中的scheme
* @param compltionBlock 支付结果回调Block
*/
- (void)payUrlOrder:(NSString *)orderStr
fromScheme:(NSString *)schemeStr
callback:(CompletionBlock)completionBlock;
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////授权1.0//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
/**
* 快登授权
* @param authInfo 需授权信息
* @param completionBlock 授权结果回调,若在授权过程中,调用方应用被系统终止,则此block无效,
需要调用方在appDelegate中调用processAuthResult:standbyCallback:方法获取授权结果
*/
- (void)authWithInfo:(APayAuthInfo *)authInfo
callback:(CompletionBlock)completionBlock;
/**
* 处理授权信息Url
*
* @param resultUrl 钱包返回的授权结果url
* @param completionBlock 授权结果回调
*/
- (void)processAuthResult:(NSURL *)resultUrl
standbyCallback:(CompletionBlock)completionBlock;
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////授权2.0//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
/**
* 快登授权2.0
*
* @param infoStr 授权请求信息字符串
* @param schemeStr 调用授权的app注册在info.plist中的scheme
* @param completionBlock 授权结果回调,若在授权过程中,调用方应用被系统终止,则此block无效,
需要调用方在appDelegate中调用processAuth_V2Result:standbyCallback:方法获取授权结果
*/
- (void)auth_V2WithInfo:(NSString *)infoStr
fromScheme:(NSString *)schemeStr
callback:(CompletionBlock)completionBlock;
/**
* 处理授权信息Url
*
* @param resultUrl 钱包返回的授权结果url
* @param completionBlock 授权结果回调
*/
- (void)processAuth_V2Result:(NSURL *)resultUrl
standbyCallback:(CompletionBlock)completionBlock;
@end
-------------------------------------------------------
Android版本号:v15.2.1
修改时间:2016-08-17
更新点:
1. 增加支付宝支付和授权2.0体系服务;
2. PayTask新增接口名称:payV2;
3. AuthTask新增接口名称:authV2;
4. 完全兼容1.0体系,1.0体系的支付和授权接口保留。
iOS版本号:v15.2.0
修改时间:2016-08-23
更新点:
1. 增加支付宝支付和授权2.0体系服务;
2. 完全兼容1.0体系,授权和支付接口保持不变;
3. 订单组装问题修复。
-------------------------------------------------------
Android版本号:v15.2.2
修改时间:2016-08-25
更新点:
1. H5支付返回结果Bug修复。
-------------------------------------------------------
Android版本号:v15.2.4
修改时间:2016-10-11
更新点:
1. 新增readme.txt;
2. 修复了2.3系统crash的问题。
-------------------------------------------------------
Android版本号:v15.2.7
修改时间:2016-11-29
更新点:
1. 增加环境设置接口。
-------------------------------------------------------
iOS版本号:v15.2.1
修改时间:2016-12-14
更新点:
1. webview屏蔽alipayjsbridge的调用。
-------------------------------------------------------
Android版本号:v15.2.8
修改时间:2016-12-22
更新点:
1. 体验优化。
-------------------------------------------------------
Android版本号:v15.3.3
修改时间:2016-03-09
更新点:
1. 加入h5支付2.0类url拦截。
-------------------------------------------------------
Android版本号:v15.3.5
修改时间:2016-04-18
更新点:
1. url拦截支付场景 - h5支付返回格式和钱包支付返回格式不一致问题修复。
-------------------------------------------------------
Android版本号:v15.3.6
修改时间:2017-05-10
更新点:
1. 版本升级到15.3.6。
2. 修复了个别商户反馈的走H5支付时获取不到return_url的问题。
3. 修复了沙箱环境fetchOrderInfoFromH5PayUrl方法无效的问题。
-------------------------------------------------------
Android 版本号:v15.3.7
修改时间:2017-06-13
更新点:
1. 修复了 H5 转 Native 支付界面中,无法响应跳转到新窗口的表单的问题。
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#import "KWMGuideVC.h" #import "KWMGuideVC.h"
#import "KWMLoginVC.h" #import "KWMLoginVC.h"
#import "KWMUserModel.h" #import "KWMUserModel.h"
#import <AlipaySDK/AlipaySDK.h>
@interface AppDelegate () @interface AppDelegate ()
...@@ -106,6 +107,25 @@ ...@@ -106,6 +107,25 @@
// [self.window makeKeyAndVisible]; // [self.window makeKeyAndVisible];
} }
//支付宝 NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{
if ([url.host isEqualToString:@"safepay"]) {
//跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
NSLog(@"result = %@",resultDic);
NSNumber *statue = [resultDic objectForKey:@"resultStatus"];
if (statue.integerValue == 9000) {
[[NSNotificationCenter defaultCenter] postNotificationName:KWMPaySuccess object:nil userInfo:nil];
}
}];
}else{//ios9.2之后的系统需要调用(官方文档没有)
return [WXApi handleOpenURL:url delegate:self];
}
return YES;
}
//微信需要重写
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{ -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
return [WXApi handleOpenURL:url delegate:self]; return [WXApi handleOpenURL:url delegate:self];
} }
...@@ -152,6 +172,18 @@ ...@@ -152,6 +172,18 @@
} }
break; break;
} }
}else if([resp isKindOfClass:[PayResp class]]){
NSString *strMsg = @"";
switch (resp.errCode) {
case WXSuccess:
NSLog(@"支付成功");
[[NSNotificationCenter defaultCenter] postNotificationName:KWMPaySuccess object:nil userInfo:nil];
break;
default:
strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr];
NSLog(@"支付错误信息%@", strMsg);
break;
}
} }
} }
......
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
#import "KWMOrder.h" #import "KWMOrder.h"
#import "KWMExchangeRateResult.h" #import "KWMExchangeRateResult.h"
#import "KWMCartResult.h" #import "KWMCartResult.h"
#import "KWMCheckoutPayResult.h"
#import "KWMWechatPayData.h"
...@@ -229,4 +232,36 @@ ...@@ -229,4 +232,36 @@
success:(void(^)(NSURLSessionDataTask *task,KWMProductResult *result))success success:(void(^)(NSURLSessionDataTask *task,KWMProductResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure; failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
/**
* 微信统一下单API
* @return NSURLSessionDataTask
*/
- (NSURLSessionDataTask *) wechatPayUnifiedOrder:(NSDictionary *)parameters
success:(void(^)(NSURLSessionDataTask *task,KWMCheckoutPayResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
/**
* 支付宝统一下单API
* @return NSURLSessionDataTask
*/
- (NSURLSessionDataTask *) aliPayUnifiedOrder:(NSDictionary *)parameters
success:(void(^)(NSURLSessionDataTask *task,KWMCheckoutPayResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
/**
* 微信订单查询API
* @return NSURLSessionDataTask
*/
- (NSURLSessionDataTask *) wechatPayOrderQuery:(NSDictionary *)parameters
success:(void(^)(NSURLSessionDataTask *task,KWMCheckoutPayResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
/**
* 支付宝订单查询API
* @return NSURLSessionDataTask
*/
- (NSURLSessionDataTask *) aliPayOrderQuery:(NSDictionary *)parameters
success:(void(^)(NSURLSessionDataTask *task,KWMCheckoutPayResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
@end @end
...@@ -206,6 +206,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -206,6 +206,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
NSAssert((result == [KWMRequestResult class] || result == [KWMRequestListResult class] NSAssert((result == [KWMRequestResult class] || result == [KWMRequestListResult class]
|| result == [KWMCheckoutPayResult class]
|| result == [KWMCemaroseResult class] || [result isSubclassOfClass:[KWMCemaroseResult class]]), || result == [KWMCemaroseResult class] || [result isSubclassOfClass:[KWMCemaroseResult class]]),
@"result class must either be KWMRequestResult or KWMRequestListResult!"); @"result class must either be KWMRequestResult or KWMRequestListResult!");
NSAssert((!model || (model && [model isSubclassOfClass:[JSONModel class]])), NSAssert((!model || (model && [model isSubclassOfClass:[JSONModel class]])),
...@@ -747,5 +748,87 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -747,5 +748,87 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
} }
/**
* 微信统一下单API
* checkout_token shopify订单token
* total_price 订单总金额
* ip_address 手机IP
* subject 订单描述
* sign 签名验证
* 签名规则
* str_sign = "ip_address=127.0.0.1&checkout_token=5173547165345&subject=test&total_price=23423&key=bd3f58f5cd3d7a217ac8c8e655ab52f8";
* sign = md5(base64_encode($str_sign));
*
* @return NSURLSessionDataTask
*/
- (NSURLSessionDataTask *) wechatPayUnifiedOrder:(NSDictionary *)parameters
success:(void(^)(NSURLSessionDataTask *task,KWMCheckoutPayResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{
NSString *apiPath = @"https://peter.tofnews.com/wechatpay/app/unified_order";
return [self startSessionTask:KWMHTTPMethodPOST
apiPath:apiPath
parameters:parameters
result:[KWMCheckoutPayResult class]
model:[KWMWechatPayData class]
success:success
failure:failure];
}
/**
* 支付宝统一下单API
* checkout_token shopify订单token
* total_price 订单总金额
* subject 订单描述
* sign 签名验证
* 签名规则
* str_sign = checkout_token=5173547165345&subject=test&total_price=23423&key=bd3f58f5cd3d7a217ac8c8e655ab52f8";
* sign = md5(base64_encode($str_sign));
*
* @return NSURLSessionDataTask
*/
- (NSURLSessionDataTask *) aliPayUnifiedOrder:(NSDictionary *)parameters
success:(void(^)(NSURLSessionDataTask *task,KWMCheckoutPayResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{
NSString *apiPath = @"https://peter.tofnews.com/alipay/app/unified_order";
return [self startSessionTask:KWMHTTPMethodPOST
apiPath:apiPath
parameters:parameters
result:[KWMCheckoutPayResult class]
model:nil
success:success
failure:failure];
}
- (NSURLSessionDataTask *) wechatPayOrderQuery:(NSDictionary *)parameters
success:(void(^)(NSURLSessionDataTask *task,KWMCheckoutPayResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{
NSString *apiPath = @"https://peter.tofnews.com/wechatpay/order/query";
return [self startSessionTask:KWMHTTPMethodPOST
apiPath:apiPath
parameters:parameters
result:[KWMCheckoutPayResult class]
model:nil
success:success
failure:failure];
}
- (NSURLSessionDataTask *) aliPayOrderQuery:(NSDictionary *)parameters
success:(void(^)(NSURLSessionDataTask *task,KWMCheckoutPayResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure{
NSString *apiPath = @"https://peter.tofnews.com/alipay/order/query";
return [self startSessionTask:KWMHTTPMethodPOST
apiPath:apiPath
parameters:parameters
result:[KWMCheckoutPayResult class]
model:nil
success:success
failure:failure];
}
@end @end
//
// KWMCheckoutPayResult.h
// iCemarose
//
// Created by HouWeiBin on 2017/6/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import <JSONModel/JSONModel.h>
/*
PS:微信支付下单API:
{"status":"success","code":1000,"message":{"appid":"wx355a497b2a2dd6d5","partnerid":"1419214902","prepayid":"wx2017061418173781efbf95390315404901","package":"Sign=WXPay","noncestr":"0f499732a49986c6a281a30db1a2b420","timestamp":1497435463,"sign":"BBB6A0E4937D6F89604B06B730A4F5D9"}}
*/
@interface KWMCheckoutPayResult : JSONModel
//结果状态。success:正常;fail:错误
@property (nonatomic) NSString<Optional> *status;
/*|code|int|1000|正常响应|
|code|int|1001|订单检索失败,未找到相应的订单数据|
|code|int|1002|请求的总金额与订单中不一致|
|code|int|1003|货币转换失败|
|code|int|1004|服务器端未开通店铺|
|code|int|1005|支付网关参数未设置|
|code|int|1006|订单已支付完成|
|code|int|1007|签名验证失败|
|code|int|1008|订单查询失败|
*/
@property (nonatomic) NSNumber<Optional> *code;
//结果详情
@property (nonatomic) id<Optional> message;
//数据--存放解析后的model。ps:只有当微信支付下单返回结果状态为成功时,message key里的数据才会是wechat pay model的数据,此时,会将message里的数据转换为对应的model并存放到data里。
@property (nonatomic) id<Optional> data;
@end
//
// KWMCheckoutPayResult.m
// iCemarose
//
// Created by HouWeiBin on 2017/6/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMCheckoutPayResult.h"
@implementation KWMCheckoutPayResult
- (instancetype)initWithDictionary:(NSDictionary *)dict
modelClass:(Class)modelClass
error:(NSError **)err {
self = [super initWithDictionary:dict error:err];
if (self) {
id messageDict = dict[@"message"];
if(modelClass && messageDict && [messageDict isKindOfClass:[NSDictionary class]]){
self.data = [self buildData:modelClass jsonDictionary:messageDict];
self.message = @"请求成功";
}else{
self.message = messageDict?messageDict:@"";
}
}
return self;
}
- (id)buildData:(Class)modelClass jsonDictionary:(NSDictionary *)jsonDictionary {
id result = nil;
if(modelClass != nil){
NSError *error;
id tmpResult = [[modelClass alloc] initWithDictionary:jsonDictionary error:&error];
if(error){
NSLog(@"buildData error: %@", [error localizedDescription]);
}else{
result = tmpResult;
}
}
return result;
}
@end
//
// KWMWechatPayData.h
// iCemarose
//
// Created by HouWeiBin on 2017/6/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMBaseModel.h"
@interface KWMWechatPayData : KWMBaseModel
/**公众账号ID*/
@property (nonatomic) NSString * _Nullable appid;
/**商户号*/
@property (nonatomic) NSString * _Nullable partnerid;
/**随机字符串*/
@property (nonatomic) NSString * _Nullable noncestr;
/**预支付交易会话标识*/
@property (nonatomic) NSString * _Nullable prepayid;
/**业务结果--不返回*/
@property (nonatomic) NSString * _Nullable resultCode;
/**签名*/
@property (nonatomic) NSString * _Nullable sign;
/**package<Sign=WXPay>**/
@property (nonatomic) NSString * _Nullable package;
/**时间戳*/
@property (nonatomic) NSInteger timestamp;
@end
//
// KWMWechatPayData.m
// iCemarose
//
// Created by HouWeiBin on 2017/6/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMWechatPayData.h"
@implementation KWMWechatPayData
@end
...@@ -13,8 +13,10 @@ ...@@ -13,8 +13,10 @@
#import "KWMSelectAddressVC.h" #import "KWMSelectAddressVC.h"
#import "KWMAddGiftCardVC.h" #import "KWMAddGiftCardVC.h"
#import "KWMShippingVC.h" #import "KWMShippingVC.h"
#import "KWMPayTypeVC.h"
@interface KWMBeforePayVC : KWMBaseVC<KWMGiftCardDelegate,KWMDiscountDelegate,KWMSelectAddressDelegate,KWMSelectShippingRateDelegate>
@interface KWMBeforePayVC : KWMBaseVC<KWMGiftCardDelegate,KWMDiscountDelegate,KWMSelectAddressDelegate,KWMSelectShippingRateDelegate,KWMPayTypeDelegate>
//沒有默認地址時,高度為37,有地址時,高度為90 //沒有默認地址時,高度為37,有地址時,高度為90
@property(nonatomic,weak) IBOutlet NSLayoutConstraint *vAddressHeight; @property(nonatomic,weak) IBOutlet NSLayoutConstraint *vAddressHeight;
...@@ -56,6 +58,8 @@ ...@@ -56,6 +58,8 @@
//快速购买购物车 //快速购买购物车
@property (nonatomic) BUYCart *fastPayCart; @property (nonatomic) BUYCart *fastPayCart;
@property (nonatomic) KWMPayType payType;
@property (strong, nonatomic) NSString *cartCookie; @property (strong, nonatomic) NSString *cartCookie;
- (IBAction)onClickPayType:(id)sender; - (IBAction)onClickPayType:(id)sender;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#import "KWMBeforePayVC.h" #import "KWMBeforePayVC.h"
#import "KWMDiscountVC.h" #import "KWMDiscountVC.h"
#import "KWMSelectAddressVC.h" #import "KWMSelectAddressVC.h"
#import "KWMPayTypeVC.h"
#import "KWMPaySuccessVC.h" #import "KWMPaySuccessVC.h"
#import "KWMShopCartModel.h" #import "KWMShopCartModel.h"
#import "KWMStringUtil.h" #import "KWMStringUtil.h"
...@@ -20,7 +19,7 @@ ...@@ -20,7 +19,7 @@
#import <RegexKitLite/RegexKitLite.h> #import <RegexKitLite/RegexKitLite.h>
#import "KWMHttpUtil.h" #import "KWMHttpUtil.h"
#import "KWMValidateUtil.h" #import "KWMValidateUtil.h"
#import "KWMPayUtil.h"
@interface KWMBeforePayVC () @interface KWMBeforePayVC ()
@property (nonatomic) BUYCustomer *customer; @property (nonatomic) BUYCustomer *customer;
...@@ -47,6 +46,22 @@ ...@@ -47,6 +46,22 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.title = @"提交订单"; self.title = @"提交订单";
//支付成功回调广播接收者 ##通过广播接受appdelegate中的支付回调。
NSNotificationCenter *notifi = [NSNotificationCenter defaultCenter];
[notifi addObserver:self selector:@selector(paySuccess) name:KWMPaySuccess object:nil];
}
-(void)dealloc{
//注销支付成功广播接收者
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter removeObserver:self
name:KWMPaySuccess
object:nil];
}
-(void)setPayType:(KWMPayType)payType{
_payType = payType;
self.lbPayType.text = [KWMPayUtil payTypeString:payType];
} }
-(void)initDefaultData{ -(void)initDefaultData{
...@@ -132,6 +147,10 @@ ...@@ -132,6 +147,10 @@
[self initData]; [self initData];
} }
-(void)kwm_onSelectPayType:(KWMPayType)payType{
self.payType = payType;
}
- (void)initData{ - (void)initData{
if(self.checkout == nil){ if(self.checkout == nil){
[self showToast:@"未成功创建订单"]; [self showToast:@"未成功创建订单"];
...@@ -336,6 +355,7 @@ ...@@ -336,6 +355,7 @@
return; return;
} }
KWMPayTypeVC *typeVC = (KWMPayTypeVC *)[KWMBaseVC findControllerBy:[KWMPayTypeVC kwmTag] fromStoryboard:@"ShopCart"]; KWMPayTypeVC *typeVC = (KWMPayTypeVC *)[KWMBaseVC findControllerBy:[KWMPayTypeVC kwmTag] fromStoryboard:@"ShopCart"];
typeVC.delegate = self;
[self.navigationController pushViewController:typeVC animated:YES]; [self.navigationController pushViewController:typeVC animated:YES];
} }
...@@ -392,6 +412,10 @@ ...@@ -392,6 +412,10 @@
[self showToast:@"请先选择地址"]; [self showToast:@"请先选择地址"];
return; return;
} }
if(self.payType == TypeNone){
[self showToast:@"请选择一种付款方式"];
return;
}
if(self.checkout.shippingRate == nil){ if(self.checkout.shippingRate == nil){
[self showToast:@"请先选择配送方式"]; [self showToast:@"请先选择配送方式"];
return; return;
...@@ -400,9 +424,20 @@ ...@@ -400,9 +424,20 @@
[self showToast:@"未成功创建支付链接"]; [self showToast:@"未成功创建支付链接"];
return; return;
} }
KWMCheckoutWebViewVC *checkoutVC = (KWMCheckoutWebViewVC *)[KWMBaseVC findControllerBy:[KWMCheckoutWebViewVC kwmTag] fromStoryboard:@"ShopCart"]; //不同的支付方式
checkoutVC.payURL = self.checkout.webCheckoutURL; switch (self.payType) {
[self.navigationController pushViewController:checkoutVC animated:YES]; case TypeCredit:
[self goToWebPay];
break;
case TypeAlipay:
[self requestAliPay];
break;
case TypeWechatPay:
[self requestWeChatPay];
break;
default:
break;
}
} }
//设置配送费到订单 //设置配送费到订单
...@@ -560,6 +595,72 @@ ...@@ -560,6 +595,72 @@
}]; }];
} }
//支付宝支付
-(void)requestAliPay{
NSDictionary *parameters = [KWMPayUtil aliPayParameters:self.checkout];
__weak KWMBeforePayVC *weakSelf = self;
void(^failure)(NSURLSessionDataTask *,NSError *) = ^(NSURLSessionDataTask *task,NSError *error){
[weakSelf hideLoading];
[weakSelf showError:error];
};
void(^success)(NSURLSessionDataTask *,KWMCheckoutPayResult *) = ^(NSURLSessionDataTask *task,KWMCheckoutPayResult *result){
[weakSelf hideLoading];
if(!result){
return;
}
if(!result.code || result.code.integerValue != 1000){
return;
}
NSString *alipayData = (NSString *)result.message;
[KWMPayUtil aliPay:alipayData callback:^(NSDictionary *resultDic) {
NSLog(@"reslut = %@",resultDic);
NSNumber *statue = [resultDic objectForKey:@"resultStatus"];
if (statue.integerValue == 9000) {
[weakSelf paySuccess];
}
}];
};
[self.api aliPayUnifiedOrder:parameters success:success failure:failure];
[self showLoading];
}
//微信支付
-(void)requestWeChatPay{
NSDictionary *parameters = [KWMPayUtil wechatPayParameters:self.checkout];
__weak KWMBeforePayVC *weakSelf = self;
void(^failure)(NSURLSessionDataTask *,NSError *) = ^(NSURLSessionDataTask *task,NSError *error){
[weakSelf hideLoading];
[weakSelf showError:error];
};
void(^success)(NSURLSessionDataTask *,KWMCheckoutPayResult *) = ^(NSURLSessionDataTask *task,KWMCheckoutPayResult *result){
[weakSelf hideLoading];
if(!result){
return;
}
if(!result.code || result.code.integerValue != 1000){
return;
}
if(result.data){
KWMWechatPayData *data = (KWMWechatPayData *)result.data;
[KWMPayUtil weChatPay:data];
}
};
[self.api wechatPayUnifiedOrder:parameters success:success failure:failure];
[self showLoading];
}
-(void)goToWebPay{
KWMCheckoutWebViewVC *checkoutVC = (KWMCheckoutWebViewVC *)[KWMBaseVC findControllerBy:[KWMCheckoutWebViewVC kwmTag] fromStoryboard:@"ShopCart"];
checkoutVC.payURL = self.checkout.webCheckoutURL;
[self.navigationController pushViewController:checkoutVC animated:YES];
}
-(void)paySuccess{
KWMPaySuccessVC *successVC = (KWMPaySuccessVC *)[KWMBaseVC findControllerBy:[KWMPaySuccessVC kwmTag] fromStoryboard:@"ShopCart"];
[self.navigationController pushViewController:successVC animated:YES];
}
////判断订单是否支付 ////判断订单是否支付
//-(void)requestCheckPay:(BUYCheckout *)checkCache{ //-(void)requestCheckPay:(BUYCheckout *)checkCache{
// [self showLoading]; // [self showLoading];
......
...@@ -8,6 +8,18 @@ ...@@ -8,6 +8,18 @@
#import "KWMBaseVC.h" #import "KWMBaseVC.h"
typedef NS_ENUM(NSInteger, KWMPayType) {
TypeNone = 0,
TypeCredit,
TypeAlipay,
TypeWechatPay
};
@protocol KWMPayTypeDelegate <NSObject>
- (void)kwm_onSelectPayType:(KWMPayType)payType;
@end
@interface KWMPayTypeVC : KWMBaseVC @interface KWMPayTypeVC : KWMBaseVC
- (IBAction)onClickWechatPay:(id)sender; - (IBAction)onClickWechatPay:(id)sender;
...@@ -16,5 +28,7 @@ ...@@ -16,5 +28,7 @@
- (IBAction)onClickCreditPay:(id)sender; - (IBAction)onClickCreditPay:(id)sender;
@property (weak, nonatomic) id<KWMPayTypeDelegate>delegate;
@end @end
...@@ -30,18 +30,26 @@ ...@@ -30,18 +30,26 @@
-(void)onClickAliPay:(id)sender{ -(void)onClickAliPay:(id)sender{
if(self.delegate){
[self.delegate kwm_onSelectPayType:TypeAlipay];
}
[[self navigationController] popViewControllerAnimated:YES]; [[self navigationController] popViewControllerAnimated:YES];
} }
-(void)onClickCreditPay:(id)sender{ -(void)onClickCreditPay:(id)sender{
if(self.delegate){
[self.delegate kwm_onSelectPayType:TypeCredit];
}
[[self navigationController] popViewControllerAnimated:YES]; [[self navigationController] popViewControllerAnimated:YES];
} }
-(void)onClickWechatPay:(id)sender{ -(void)onClickWechatPay:(id)sender{
if(self.delegate){
[self.delegate kwm_onSelectPayType:TypeWechatPay];
}
[[self navigationController] popViewControllerAnimated:YES]; [[self navigationController] popViewControllerAnimated:YES];
} }
@end @end
//
// KWMPayUtil.h
// iCemarose
//
// Created by HouWeiBin on 2017/6/15.
// Copyright © 2017年 kollway. All rights reserved.
//
// 支付相关工具类
#import "KWMWechatPayData.h"
#import "KWMPayTypeVC.h"
#import <Foundation/Foundation.h>
#import <Buy/Buy.h>
#import <AlipaySDK/AlipaySDK.h>
#import "WXApi.h"
@interface KWMPayUtil : NSObject
+ (NSString *) payTypeString:(KWMPayType)payType;
//构建微信支付下单数据
+ (NSDictionary *) wechatPayParameters:(BUYCheckout *)checkout;
//构建支付宝下单数据
+ (NSDictionary *) aliPayParameters:(BUYCheckout *)checkout;
//调用微信SDK
+ (void)weChatPay:(KWMWechatPayData *)wechatData;
//调用支付宝SDK
+ (void)aliPay:(NSString *)alipayData callback:(CompletionBlock)callback;
@end
//
// KWMPayUtil.m
// iCemarose
//
// Created by HouWeiBin on 2017/6/15.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMPayUtil.h"
#import "KWMStringUtil.h"
@implementation KWMPayUtil
+(NSString *)payTypeString:(KWMPayType)payType{
NSString *payTypeString = @"";
switch (payType) {
case TypeNone:
payTypeString = @"请选择一种付款方式";
break;
case TypeCredit:
payTypeString = @"信用卡支付";
break;
case TypeWechatPay:
payTypeString = @"微信支付";
break;
case TypeAlipay:
payTypeString = @"支付宝支付";
break;
}
return payTypeString;
}
+(NSDictionary *)wechatPayParameters:(BUYCheckout *)checkout{
//这是测试商店的单,先用来测试
NSString *checkout_token = @"bfa0423b2b51657098d581a93e78bc00";
NSString *total_price = @"127.00";
//NSString *checkout_token = checkout.token;
//NSString *total_price = [NSString stringWithFormat:@"%.2f",checkout.totalPrice.floatValue];
NSString *ip_address = @"127.0.0.1";
//先写test,后面改成正式的订单描述
NSString *subject = @"test";
NSString *before_sign = [NSString stringWithFormat:@"checkout_token=%@&ip_address=%@&subject=%@&total_price=%@&key=%@",
checkout_token,ip_address,subject,total_price,User_Pay_KEY];
NSString *base64String = [KWMStringUtil BASE64:before_sign];
NSString *sign = [KWMStringUtil MD5:base64String];
NSDictionary *parameters = @{
@"ip_address":ip_address,
@"checkout_token":checkout_token,
@"subject":subject,
@"total_price":total_price,
@"sign":sign
};
return parameters;
}
+(NSDictionary *)aliPayParameters:(BUYCheckout *)checkout{
//这是测试商店的单,先用来测试
NSString *checkout_token = @"bfa0423b2b51657098d581a93e78bc00";
NSString *total_price = @"127.00";
//NSString *checkout_token = checkout.token;
//NSString *total_price = [NSString stringWithFormat:@"%.2f",checkout.totalPrice.floatValue];
NSString *subject = @"test";
NSString *before_sign = [NSString stringWithFormat:@"checkout_token=%@&subject=%@&total_price=%@&key=%@",
checkout_token,subject,total_price,User_Pay_KEY];
NSString *base64String = [KWMStringUtil BASE64:before_sign];
NSString *sign = [KWMStringUtil MD5:base64String];
NSDictionary *parameters = @{
@"checkout_token":checkout_token,
@"subject":subject,
@"total_price":total_price,
@"sign":sign
};
return parameters;
}
+(void)weChatPay:(KWMWechatPayData *)wechatData{
if(wechatData){
PayReq *request = [[PayReq alloc] init];
request.openID = wechatData.appid;
request.partnerId = wechatData.partnerid;
request.prepayId= wechatData.prepayid;
request.package = wechatData.package;
request.nonceStr= wechatData.noncestr;
request.timeStamp= wechatData.timestamp;
request.sign= wechatData.sign;
[WXApi sendReq:request];
}
}
+(void)aliPay:(NSString *)alipayData callback:(CompletionBlock)callback{
if(![KWMStringUtil isEmpty:alipayData]){
NSString *appScheme = @"iCemarose";
[[AlipaySDK defaultService] payOrder:alipayData fromScheme:appScheme callback:callback];
}
}
@end
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
@interface KWMStringUtil : NSObject @interface KWMStringUtil : NSObject
+ (NSString *)MD5:(NSString *)input; + (NSString *)MD5:(NSString *)input;
+ (NSString *)BASE64:(NSString *)input;
/**是否是空字符串*/ /**是否是空字符串*/
+ (BOOL)isEmpty:(NSString *)input; + (BOOL)isEmpty:(NSString *)input;
/**是否是空白(有空格都是)的字符串*/ /**是否是空白(有空格都是)的字符串*/
......
...@@ -30,6 +30,14 @@ static NSDateFormatter *monthDayFormatter; ...@@ -30,6 +30,14 @@ static NSDateFormatter *monthDayFormatter;
return [input sam_MD5Digest]; return [input sam_MD5Digest];
} }
+ (NSString *)BASE64:(NSString *)input {
if(!input){
return input;
}
return [input sam_base64EncodedString];
}
+ (BOOL)isEmpty:(NSString *)input { + (BOOL)isEmpty:(NSString *)input {
return [input isKindOfClass:[NSNull class]] || input == nil || [input length] <= 0; return [input isKindOfClass:[NSNull class]] || input == nil || [input length] <= 0;
} }
......
...@@ -36,32 +36,29 @@ ...@@ -36,32 +36,29 @@
#define KWMNoCollect 7 #define KWMNoCollect 7
#define KWMReceiverRedPoint @"KWMReceiverRedPoint"
#define KEY_USER_RED_POINT_COMMENT_MESSAGE @"KEY_USER_RED_POINT_COMMENT_MESSAGE"
#define KEY_USER_RED_POINT_FANS_MESSAGE @"KEY_USER_RED_POINT_FANS_MESSAGE"
#define KEY_USER_RED_POINT_LIKE_REWARD_MESSAGE @"KEY_USER_RED_POINT_LIKE_REWARD_MESSAGE"
#define KEY_USER_RED_POINT_COLLECT_MESSAGE @"KEY_USER_RED_POINT_COLLECT_MESSAGE"
#define KWMReceiverPush @"KWMReceiverPush" #define KWMReceiverPush @"KWMReceiverPush"
#define KWMReceiverNoLogin @"KWMReceiverNoLogin" #define KWMReceiverNoLogin @"KWMReceiverNoLogin"
#define KWMPaySuccess @"KWMPaySuccess"
#define KEY_USER_DEFAULT_ACCOUNT @"KEY_USER_DEFAULT_ACCOUNT" #define KEY_USER_DEFAULT_ACCOUNT @"KEY_USER_DEFAULT_ACCOUNT"
#define KEY_USER_REGISTER @"KEY_USER_REGISTER" #define KEY_USER_REGISTER @"KEY_USER_REGISTER"
#define UMAppKey @"57551aaee0f55aea54000a83" #define UMAppKey @"##"
#define UmengChannel @"C001" #define UmengChannel @"C001"
#define JPUSHKey @"35f3186c1b31d56a8f88033c" #define JPUSHKey @"##"
//正式的 QQ app id //正式的 QQ app id
#define QQAppId @"1105432469" #define QQAppId @"##"
#define QQAppKey @"9Fh1cjV39jKenBUM" #define QQAppKey @"##"
//正式的微信key //正式的微信key
#define WechatAppKey @"wx355a497b2a2dd6d5" #define WechatAppKey @"wx355a497b2a2dd6d5"
#define WechatSecret @"7bb8615cdb4d750b66b653385e641f15"
//Cemarose key--chinese login 需要的key //Cemarose key--chinese login 需要的key
#define Cemarose_KEY @"4a119ac523d53c98bbd2983b798a0d53" #define Cemarose_KEY @"4a119ac523d53c98bbd2983b798a0d53"
#define User_Pay_KEY @"bd3f58f5cd3d7a217ac8c8e655ab52f8"
//// ////
////测试 ////测试
......
...@@ -35,6 +35,14 @@ ...@@ -35,6 +35,14 @@
<string>Editor</string> <string>Editor</string>
<key>CFBundleURLSchemes</key> <key>CFBundleURLSchemes</key>
<array> <array>
<string>iCemarose</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>cemarose</string> <string>cemarose</string>
</array> </array>
</dict> </dict>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment