Commit 2bafe321 by lee

u

parents fb8d6345 64bfda26
......@@ -14,6 +14,7 @@ pod 'SAMKeychain'
pod 'RXCollections','~> 1.0'
pod 'TOWebViewController'
pod 'SDCycleScrollView'
#pod 'AFNetworking','~> 3.1'
pod 'PPNetworkHelper'
pod 'JSONModel','~> 1.7.0'
......
......@@ -713,8 +713,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
- (NSURLSessionDataTask *)getHomeDataWithSuccess:(void (^)(NSURLSessionDataTask *, KWMHomeDataResult *))success failure:(void (^)(NSURLSessionDataTask *, NSError *))failure {
NSInteger st = [[NSDate date] timeIntervalSince1970];
// st = st - st % 86400 - 28800;
// FIXME: 这里改了再发版本
NSString *apiPath = [NSString stringWithFormat:@"https://ogbgohpla.qnssl.com/App.Home.json.bak?st=%ld",st];
NSString *apiPath = [NSString stringWithFormat:@"https://ogbgohpla.qnssl.com/App.Home.test.json?st=%zi",st];
return [self startSessionTask:KWMHTTPMethodGET apiPath:apiPath parameters:nil result:[KWMHomeDataResult class] model:nil success:success failure:failure];
}
......@@ -875,9 +874,10 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
/**
* 通过checkout_token查询shopify订单API
* @param checkout_token shopify订单token
* @param out_trade_no 订单支付编号
* @param sign 签名验证
* 签名规则:
* str_sign = checkout_token=5173547165345&key=bd3f58f5cd3d7a217ac8c8e655ab52f8";
* str_sign = checkout_token=5173547165345&out_trade_no=201708011602269375&key=bd3f58f5cd3d7a217ac8c8e655ab52f8";
* sign = md5(base64_encode($str_sign));
*/
- (NSURLSessionDataTask *) appOrderQuery:(NSDictionary *)parameters
......
......@@ -30,6 +30,9 @@
|code|int|1006|订单已支付完成|
|code|int|1007|签名验证失败|
|code|int|1008|订单查询失败|
|code|int|1009|订单创建失败|
|code|int|1010|必要参数缺失|
|code|int|1012|商品数量不足|
*/
@property (nonatomic) NSNumber<Optional> *code;
......@@ -39,4 +42,7 @@
//数据--存放解析后的model。ps:只有当微信支付下单返回结果状态为成功时,message key里的数据才会是wechat pay model的数据,此时,会将message里的数据转换为对应的model并存放到data里。
@property (nonatomic) id<Optional> data;
//商品缺货时的variantId
@property (nonatomic) NSNumber<Optional> *variantId;
@end
......@@ -19,4 +19,6 @@
//链接
@property (nonatomic) NSString *url;
@property (nonatomic) NSString <Optional> *action;
@end
......@@ -14,4 +14,6 @@
@property (nonatomic) KWMWechatPayData *wechatPayData;
@property (nonatomic) NSString *outTradeNo;
@end
......@@ -20,4 +20,6 @@
@property (nonatomic) KWMHotSales *hot_sales;
@property (nonatomic) NSArray <KWMAdvertisement,Optional> *hot_sales_ads;
@end
......@@ -26,6 +26,7 @@
@property (nonatomic) NSString * _Nullable package;
/**时间戳*/
@property (nonatomic) NSInteger timestamp;
/**微信订单编号*/
@property (nonatomic) NSString * _Nullable outTradeNo;
@end
......@@ -124,7 +124,7 @@
return m;
}];
self.selectedCategory = self.categories.firstObject;
NSIndexPath * path = [NSIndexPath indexPathForItem:1 inSection:0];
NSIndexPath * path = [NSIndexPath indexPathForItem:0 inSection:0];
[self.tbvLeftCategory selectRowAtIndexPath:path animated:YES scrollPosition:UITableViewScrollPositionTop];
}
......
......@@ -276,6 +276,9 @@
}
- (void)showDialog:(NSString *)message{
if([KWMStringUtil isEmpty:message]){
return;
}
PSPDFAlertView *alertView = [[PSPDFAlertView alloc] initWithTitle:message];
[alertView addButtonWithTitle:@"确定" block:nil];
[alertView show];
......
......@@ -7,7 +7,6 @@
//
#import "KWMBaseModel.h"
#import "KWMBannerView.h"
#import "KWMAdvertisement.h"
......@@ -17,13 +16,10 @@
@end
@interface KWMAdHeader : UIView<KWMBannerViewDelegate>
@interface KWMAdHeader : UIView
+ (NSString *)kwmTag;
-(void)startBannerTimer;
-(void)endBannerTimer;
@property (nonatomic) NSArray<KWMAdvertisement *> *adArray;
......
......@@ -8,11 +8,12 @@
#import "KWMAdHeader.h"
#import "UIImageView+WebCache.h"
#import <SDCycleScrollView/SDCycleScrollView.h>
@interface KWMAdHeader()
@interface KWMAdHeader()<SDCycleScrollViewDelegate>
@property (nonatomic,strong) KWMBannerView *bannerView;
@property (nonatomic,strong) SDCycleScrollView *focusView;
@end
......@@ -45,54 +46,48 @@
}
-(void)addView{
self.bannerView = [[KWMBannerView alloc]initWithFrame:self.frame];
self.bannerView.delegate = self;
[self addSubview:self.bannerView];
// self.bannerView = [[KWMBannerView alloc]initWithFrame:self.frame];
// self.bannerView.delegate = self;
// [self addSubview:self.bannerView];
[self initFocusView];
}
-(void)startBannerTimer{
[self.bannerView addTimer];
}
-(void)endBannerTimer{
[self.bannerView removeTimer];
}
-(void)setAdArray:(NSArray<KWMAdvertisement *> *)adArray{
_adArray = adArray;
[self.bannerView reloadData];
// [self.bannerView reloadData];
_focusView.imageURLStringsGroup = [adArray rx_mapWithBlock:^id(KWMAdvertisement *each) {
return each.image;
}];
}
#pragma mark - KWMBannerViewDelegate
-(UIView *)bannerView:(KWMBannerView *)bannerView reusingView:(UIView *)reusingView pageAtIndex:(NSInteger)index{
UIView *itemView = reusingView?reusingView:nil;
UIImageView *topBannerItem = nil;
if(!itemView){
topBannerItem = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, bannerView.frame.size.width, bannerView.frame.size.height)];
}else{
topBannerItem = (UIImageView *)itemView;
-(void)initFocusView {
if (!_focusView) {
_focusView = [[SDCycleScrollView alloc] init];
_focusView.delegate = self;
_focusView.translatesAutoresizingMaskIntoConstraints = NO;
_focusView.frame = CGRectMake(0, 0, 375, 190);
_focusView.autoScrollTimeInterval = 3;
_focusView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
_focusView.pageDotImage = [UIImage imageNamed:@"ic_page_1"];
_focusView.currentPageDotImage = [UIImage imageNamed:@"ic_page_2"];
_focusView.placeholderImage = [UIImage imageNamed:@"ic_loading"];
_focusView.backgroundColor = [UIColor whiteColor];
[self addSubview:_focusView];
NSDictionary *views = @{ @"v": _focusView };
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[v]|" options:0 metrics:nil views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[v]|" options:0 metrics:nil views:views]];
}
KWMAdvertisement *ad = [self.adArray objectAtIndex:index];
NSURL *imageURL = [NSURL URLWithString:ad.image];
[topBannerItem sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
//topBannerItem.image = [UIImage imageNamed:@"test_banner_1"];
topBannerItem.contentMode=UIViewContentModeScaleAspectFill;
itemView = topBannerItem;
return itemView;
}
-(NSInteger)numberOfPagesForBanner:(KWMBannerView *)bannerView{
return self.adArray?self.adArray.count:0;
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
[self.delegate kwm_gotoWebView:self.adArray[index].url];
}
-(void)bannerView:(KWMBannerView *)bannerView onClickPage:(NSInteger)index{
KWMAdvertisement *ad = [self.adArray objectAtIndex:index];
if(self.delegate){
[self.delegate kwm_gotoWebView:ad.url];
}
}
//-(void)bannerView:(KWMBannerView *)bannerView onClickPage:(NSInteger)index{
// KWMAdvertisement *ad = [self.adArray objectAtIndex:index];
// if(self.delegate){
// [self.delegate kwm_gotoWebView:ad.url];
// }
//}
@end
......@@ -11,6 +11,8 @@
@protocol KWMClothingSetsDelegate <NSObject>
- (void)kwm_onClickFocusImage;
- (void)kwm_onClickProduct:(BUYProduct *)product;
- (void)kwm_gotoClothingSetsPage;
......
......@@ -124,5 +124,11 @@
}
}
#pragma mark - action
-(IBAction) focusImageAction:(id)sender {
[self.delegate kwm_onClickFocusImage];
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
......@@ -25,8 +25,12 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="nBP-0Q-eKB" userLabel="推荐搭配title view">
<rect key="frame" x="0.0" y="0.0" width="375" height="190"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Xzr-zM-E25">
<imageView clipsSubviews="YES" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Xzr-zM-E25">
<rect key="frame" x="0.0" y="0.0" width="375" height="190"/>
<gestureRecognizers/>
<connections>
<outletCollection property="gestureRecognizers" destination="wLm-4C-MJb" appends="YES" id="eW6-hN-Ap5"/>
</connections>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic_triangle" translatesAutoresizingMaskIntoConstraints="NO" id="LvJ-FP-Yc1">
<rect key="frame" x="177" y="181" width="20" height="10"/>
......@@ -84,6 +88,11 @@
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="34.5" y="107"/>
</view>
<tapGestureRecognizer id="wLm-4C-MJb">
<connections>
<action selector="focusImageAction:" destination="-1" id="ds0-ME-0oT"/>
</connections>
</tapGestureRecognizer>
</objects>
<resources>
<image name="ic_triangle" width="21" height="11"/>
......
......@@ -7,8 +7,8 @@
//
#import <UIKit/UIKit.h>
#import "KWMBannerView.h"
#import <Buy/Buy.h>
#import "KWMAdvertisement.h"
......@@ -16,21 +16,20 @@
- (void)kwm_onClickProduct:(BUYProduct *)product;
- (void)kwm_onClickHotSalesAd:(KWMAdvertisement *) ad;
@end
@interface KWMHotSalesHeader : UIView<KWMBannerViewDelegate>
@interface KWMHotSalesHeader : UIView
+ (NSString *)kwmTag;
-(void)startBannerTimer;
-(void)endBannerTimer;
@property(nonatomic,weak) id<KWMHotSalesDelegate> delegate;
@property(nonatomic) NSArray<BUYProduct *> *singleShowArray;
@property(nonatomic) NSArray<BUYProduct *> *bannerArray;
@property(nonatomic) NSArray<KWMAdvertisement *> *bannerArray;
@property(nonatomic,readonly) NSInteger actrualHeight;
......
......@@ -10,12 +10,15 @@
#import "KWMProductBannerItemView.h"
#import "UIImageView+WebCache.h"
#import "KWMNewHomeCell.h"
#import <SDCycleScrollView/SDCycleScrollView.h>
@interface KWMHotSalesHeader()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@interface KWMHotSalesHeader()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,SDCycleScrollViewDelegate>
@property (nonatomic,weak) IBOutlet UIView *vView;
@property (nonatomic,weak) IBOutlet KWMBannerView *bannerView;
@property (nonatomic,weak) IBOutlet UIView *bannerView;
@property (nonatomic, strong) SDCycleScrollView *focusView;
@property (nonatomic,weak) IBOutlet UICollectionView *singleShowView;
......@@ -71,30 +74,37 @@
-(void)initView{
UINib *nib = [UINib nibWithNibName:@"KWMNewHomeCell" bundle:nil];
[self.singleShowView registerNib:nib forCellWithReuseIdentifier:@"KWMNewHomeCell"];
// [self.singleShowView registerNib:nib forCellReuseIdentifier:@"KWMNewHomeCell"];
// [self.singleShowView registerNib:[[[NSBundle mainBundle]loadNibNamed:@"KWMNewHomeCell" owner:self options:nil] firstObject] forCellReuseIdentifier:@"KWMNewHomeCell"];
self.singleShowView.delegate = self;
self.singleShowView.dataSource = self;
// self.singleShowView.collectionViewLayout.collectionViewContentSize = CGSizeMake(UI_SCREEN_WIDTH - 16, UI_SCREEN_WIDTH + 58);
// self.singleShowView.collectionViewLayout = [UICollectionViewLayout alloc]
self.bannerView.delegate = self;
self.heightBannerView.constant = 0;
self.heightSingleShowView.constant = 0;
}
-(void)startBannerTimer{
[self.bannerView addTimer];
}
-(void)endBannerTimer{
[self.bannerView removeTimer];
-(void)initFocusView {
if (!_focusView) {
_focusView = [[SDCycleScrollView alloc] init];
_focusView.delegate = self;
_focusView.translatesAutoresizingMaskIntoConstraints = NO;
_focusView.frame = CGRectMake(0, 0, 375, 190);
_focusView.autoScrollTimeInterval = 3;
_focusView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
_focusView.pageDotImage = [UIImage imageNamed:@"ic_page_1"];
_focusView.currentPageDotImage = [UIImage imageNamed:@"ic_page_2"];
[self.bannerView addSubview:_focusView];
NSDictionary *views = @{ @"v": _focusView };
[self.bannerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[v]|" options:0 metrics:nil views:views]];
[self.bannerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[v]|" options:0 metrics:nil views:views]];
}
}
-(void)setBannerArray:(NSArray *)bannerArray{
_bannerArray = bannerArray;
if(bannerArray && bannerArray.count > 0){
[self initFocusView];
self.focusView.imageURLStringsGroup = [bannerArray rx_mapWithBlock:^id(KWMAdvertisement *each) {
return each.image;
}];
self.heightBannerView.constant = 190;
[self.bannerView reloadData];
}else{
self.heightBannerView.constant = 0;
}
......@@ -103,7 +113,7 @@
-(void)setSingleShowArray:(NSArray *)singleShowArray{
_singleShowArray = singleShowArray ? singleShowArray : [NSArray array];
NSInteger itemWidth = UI_SCREEN_WIDTH - 16;
// NSInteger itemWidth = UI_SCREEN_WIDTH - 16;
NSInteger itemHeight = UI_SCREEN_WIDTH + 58;
// for(int i=0;i<singleShowArray.count;i++){
......@@ -143,28 +153,15 @@
}
#pragma mark - KWMBannerViewDelegate
-(UIView *)bannerView:(KWMBannerView *)bannerView reusingView:(UIView *)reusingView pageAtIndex:(NSInteger)index{
UIView *itemView = reusingView?reusingView:nil;
KWMProductBannerItemView *productBannerItem = nil;
if(!itemView){
productBannerItem = [[KWMProductBannerItemView alloc]initWithFrame:CGRectMake(0, 0, bannerView.frame.size.width, bannerView.frame.size.height)];
}else{
productBannerItem = (KWMProductBannerItemView *)itemView;
}
itemView = productBannerItem;
return itemView;
}
-(NSInteger)numberOfPagesForBanner:(KWMBannerView *)bannerView{
return self.bannerArray?self.bannerArray.count:0;
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
[self.delegate kwm_onClickHotSalesAd:self.bannerArray[index]];
}
-(void)bannerView:(KWMBannerView *)bannerView onClickPage:(NSInteger)index{
BUYProduct *product = [self.bannerArray objectAtIndex:index];
if(self.delegate){
[self.delegate kwm_onClickProduct:product];
}
}
//-(void)bannerView:(KWMBannerView *)bannerView onClickPage:(NSInteger)index{
// KWMAdvertisement *adv = [self.bannerArray objectAtIndex:index];
// [self.delegate kwm_onClickFocusImage:adv];
//}
......
......@@ -60,7 +60,7 @@
<constraint firstItem="ILX-tg-IwY" firstAttribute="centerY" secondItem="d0n-L5-xP1" secondAttribute="centerY" id="r8p-Ru-bb6"/>
</constraints>
</view>
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ruv-UI-DGw" userLabel="热卖单品Banner" customClass="KWMBannerView">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ruv-UI-DGw" userLabel="热卖单品Banner">
<rect key="frame" x="0.0" y="60" width="375" height="190"/>
<color key="backgroundColor" red="0.90588235289999997" green="0.81960784310000001" blue="0.74117647060000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
......
......@@ -79,12 +79,6 @@ typedef enum{
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if(self.adHeader){
[self.adHeader startBannerTimer];
}
if(self.hotSalesHeader){
[self.hotSalesHeader startBannerTimer];
}
[self.navigationController setNavigationBarHidden:YES];
if (self.titleView) {
NSInteger count = [[KWMShoppingCart sharedInstance] count].integerValue;
......@@ -96,12 +90,6 @@ typedef enum{
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
if(self.adHeader){
[self.adHeader endBannerTimer];
}
if(self.hotSalesHeader){
[self.hotSalesHeader endBannerTimer];
}
}
......@@ -167,7 +155,11 @@ typedef enum{
#pragma mark - KWMMenuDelegate
-(void)kwm_onClickHotMenu{
if([TestModel isEqualToString:@"YES"]){
[self openURLWithString:[NSString stringWithFormat:@"https://cemarose.myshopify.com/products/%@",@"17618-01"]];
}else{
[self openURLWithString:@"https://cemarose.myshopify.com/collections/new?title=最新单品"];
}
}
-(void)kwm_onClickNewMenu{
......@@ -194,6 +186,16 @@ typedef enum{
[self openURLWithString:@"https://cemarose.myshopify.com/collections/hot-sell-app?title=主推单品"];
}
-(void)kwm_onClickHotSalesAd:(KWMAdvertisement *)ad {
[self openURLWithString:ad.url];
}
-(void)kwm_onClickFocusImage {
if (![KWMStringUtil isBlank:self.homeData.clothing_sets.action]) {
[self openURLWithString:self.homeData.clothing_sets.action];
}
}
-(void)kwm_gotoClothingSetsPage{
// [self openURLWithString:[NSString stringWithFormat:@"https://cemarose.myshopify.com/collections/%@",self.clotingSetsHandle]];
[self openURLWithString:self.homeData.clothing_sets.url];
......@@ -396,6 +398,7 @@ typedef enum{
_homeData = homeData;
// [self.homeData.ad_banner[0] setUrl:@"https://www.cemarose.cn/collections/skirts/girls"];
self.adHeader.adArray = self.homeData.ad_banner;
self.hotSalesHeader.bannerArray = self.homeData.hot_sales_ads;
// self.homeData.hot_sales.single_show_count = @(1);
self.clothingSetsHeader.headerImage = self.homeData.clothing_sets.image;
// self.homeData.clothing_sets.url =@"https://www.cemarose.cn/collections/skirts/girls+spring-summer-2016?title=ml";
......@@ -411,7 +414,6 @@ typedef enum{
}
}
[self requestProductWithHandle:@"products-list-app-homepage" tags:nil valueKeyPath:@"productArray"];
NSLog(@"path:%@",clothingParam);
}
- (void)setProductArray:(NSArray<BUYProduct *> *)productArray {
......
......@@ -40,6 +40,7 @@
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO];
[self setTotalPrice];
}
- (IBAction)onClickComplete:(id)sender{
......@@ -52,7 +53,6 @@
[self.tbvWish registerNib:[UINib nibWithNibName:NSStringFromClass([KWMWishCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([KWMWishCell class])];
self.wishArray = [NSMutableArray array];
self.productArray = [NSMutableArray array];
[self setTotalPrice];
}
-(void)removeWish:(NSNumber *)variantId{
......@@ -92,6 +92,7 @@
wish.variantSku = variant.sku;
wish.variantTitle = variant.title;
[self.tbvWish reloadData];
break;
}
}
}
......
......@@ -570,8 +570,6 @@
if(this.checkout.shippingAddress && !this.checkout.shippingRate) {
[this requestShippingData];
}
//排除已被支付的checkout的可能性
[this requestOrderPayResult];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[this hideLoading];
[this showError:error];
......@@ -622,13 +620,11 @@
}
-(void)requestOrderPayResult{
//微信支付,用户支付后,当用户没有点击完成按钮,而是直接使用home键,或者点击状态栏左上角返回APP订单页面时,微信的回调不会调用,而很容易出现订单结果丢失的情况,所以需要再确认一次订单是否完成。
//微信支付,用户支付后,当用户没有点击完成按钮,而是直接使用home键,或者点击状态栏左上角返回APP订单页面时,微信的回调不会调用,而很容易出现本地订单结果回调丢失的情况,所以需要再确认一次订单是否完成。
//支付宝暂时没有这种问题。
//另外用到的情况:上次被支付的订单,因某些突发原因没从缓存清除。
//if(self.beforePayData && self.beforePayData.wechatPayData && self.checkout){
if(self.checkout){
NSDictionary *parameters = [KWMPayUtil payResultParameters:self.checkout];
self.beforePayData.wechatPayData = nil;
if(self.beforePayData && ![KWMStringUtil isEmpty:self.beforePayData.outTradeNo] && self.checkout){
NSDictionary *parameters = [KWMPayUtil payResultParameters:self.checkout tradeNo:self.beforePayData.outTradeNo];
self.beforePayData.outTradeNo = @"";
__weak KWMBeforePayVC *weakSelf = self;
void(^failure)(NSURLSessionDataTask *,NSError *) = ^(NSURLSessionDataTask *task,NSError *error){
//[weakSelf showError:error];
......@@ -641,7 +637,7 @@
return;
}
if(result.data){
KWMOrderPaid *data = (KWMOrderPaid *)result.data;
//KWMOrderPaid *data = (KWMOrderPaid *)result.data;
[weakSelf paySuccess];
}
};
......@@ -659,11 +655,12 @@
};
void(^success)(NSURLSessionDataTask *,KWMCheckoutPayResult *) = ^(NSURLSessionDataTask *task,KWMCheckoutPayResult *result){
[weakSelf hideLoading];
if(!result){
if(!(result && result.code)){
return;
}
if(!result.code || result.code.integerValue != 1000){
NSLog(@"error: %@",result.message);
if(result.code.integerValue != 1000){
NSString *message = [KWMPayUtil payErrorMessage:weakSelf.checkout errorResult:result];
[weakSelf showDialog:message];
return;
}
NSString *alipayData = (NSString *)result.message;
......@@ -694,16 +691,18 @@
};
void(^success)(NSURLSessionDataTask *,KWMCheckoutPayResult *) = ^(NSURLSessionDataTask *task,KWMCheckoutPayResult *result){
[weakSelf hideLoading];
if(!result){
if(!(result && result.code)){
return;
}
if(!result.code || result.code.integerValue != 1000){
if(result.code.integerValue != 1000){
NSString *message = [KWMPayUtil payErrorMessage:weakSelf.checkout errorResult:result];
[weakSelf showDialog:message];
return;
}
if(result.data){
KWMWechatPayData *data = (KWMWechatPayData *)result.data;
[KWMPayUtil weChatPay:data];
weakSelf.beforePayData.wechatPayData = data;
weakSelf.beforePayData.outTradeNo = data.outTradeNo;
}
};
[self.api wechatPayUnifiedOrder:parameters success:success failure:failure];
......
......@@ -26,7 +26,7 @@
+ (NSDictionary *) aliPayParameters:(BUYCheckout *)checkout;
//构建支付结果查询数据
+(NSDictionary *)payResultParameters:(BUYCheckout *)checkout;
+(NSDictionary *)payResultParameters:(BUYCheckout *)checkout tradeNo:(NSString *)tradeNo;
//调用微信SDK
+ (void)weChatPay:(KWMWechatPayData *)wechatData;
......@@ -34,6 +34,8 @@
//调用支付宝SDK
+ (void)aliPay:(NSString *)alipayData callback:(CompletionBlock)callback;
//支付失败提示信息
+(NSString *)payErrorMessage:(BUYCheckout *)checkout errorResult:(KWMCheckoutPayResult *)errorResult;
@end
......@@ -81,22 +81,21 @@
return parameters;
}
//现在在两个地方会用到这条api
//1,支付后切换回到APP
//2,beforepay创建/复用旧checkout时,判断该checkout是否被支付了,但是之前没清空。
+(NSDictionary *)payResultParameters:(BUYCheckout *)checkout{
//微信支付后直接切换回到APP会调用此方法
+(NSDictionary *)payResultParameters:(BUYCheckout *)checkout tradeNo:(NSString *)tradeNo{
#if DEBUG
NSString *checkout_token = checkout.token;
#else
NSString *checkout_token = checkout.token;
#endif
NSString *before_sign = [NSString stringWithFormat:@"checkout_token=%@&key=%@",
checkout_token,User_Pay_KEY];
NSString *out_trade_no = tradeNo?:@"";
NSString *before_sign = [NSString stringWithFormat:@"checkout_token=%@&out_trade_no=%@&key=%@",
checkout_token,out_trade_no,User_Pay_KEY];
NSString *base64String = [KWMStringUtil BASE64:before_sign];
NSString *sign = [KWMStringUtil MD5:base64String];
NSDictionary *parameters = @{
@"checkout_token":checkout_token,
@"out_trade_no":out_trade_no,
@"sign":sign
};
return parameters;
......@@ -123,4 +122,63 @@
}
}
/*
|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|订单查询失败|
|code|int|1009|订单创建失败|
|code|int|1010|必要参数缺失|
|code|int|1012|商品数量不足|
*/
+(NSString *)payErrorMessage:(BUYCheckout *)checkout errorResult:(KWMCheckoutPayResult *)errorResult{
if(!errorResult){
return @"";
}
if(errorResult.code){
switch (errorResult.code.integerValue) {
case 1000:
return @"";
case 1001:
return @"订单检索失败,未找到相应的订单数据";
case 1002:
return @"请求的总金额与订单中不一致";
case 1003:
return @"货币转换失败";
case 1004:
return @"服务器端未开通店铺";
case 1005:
return @"支付网关参数未设置";
case 1006:
return @"订单已支付完成";
case 1007:
return @"签名验证失败";
case 1008:
return @"订单查询失败";
case 1009:
return @"订单创建失败";
case 1010:
return @"必要参数缺失";
case 1012:
if(!(checkout && errorResult.variantId) ){
return @"";
}
for(BUYCartLineItem *item in checkout.lineItemsArray){
if([item.variantId isEqualToNumber:errorResult.variantId]){
NSString *message = [NSString stringWithFormat:@"商品“%@/%@”数量不足",item.title,item.variantTitle];
return message;
}
}
return @"商品数量不足";
}
}
return @"";
}
@end
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.2</string>
<string>1.5.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
......@@ -56,7 +56,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2017072520</string>
<string>2017080413</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
......
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