重庆迈尖科技有限公司
2018-07-02 1d560171b17226a01c43475273a22ae3086d589f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
//  WXUtilModule.m
//  MIduo
//
//  Created by 重庆迈尖科技有限公司 on 2018/6/28.
//  Copyright © 2018年 yeshi. All rights reserved.
//
 
#import "WXUtilModule.h"
#import "ShonpingShareViewController.h"
#import "SureWebViewController.h"
#import "GoodDeTrViewController.h"
 
@implementation WXUtilModule
 
@synthesize weexInstance;
 
/// 生成签名
WX_EXPORT_METHOD_SYNC(@selector(getSign:))
/// 跳转到商品过度页
WX_EXPORT_METHOD(@selector(jumpGoodsSplash:))
/// 跳转原有的商品详情
WX_EXPORT_METHOD(@selector(jumpGoodsDetail:))
/// 跳转网页
WX_EXPORT_METHOD(@selector(jumpWeb:))
/// 分享
WX_EXPORT_METHOD(@selector(share:))
/// 结束当前页面
WX_EXPORT_METHOD(@selector(finishPage))
 
#pragma mark --- 生成签名 ---
- (NSString *)getSign:(NSString *)result {
    
    // 将JSON字符串转化为NSData类型
    NSData *data = [result dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *tempParms = [NSJSONSerialization JSONObjectWithData:data
                                                              options:0
                                                                error:nil];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:tempParms];
    
    
    NSString *sign = [self sortingDictionaryWithdic:dic];
    
    return sign;
}
 
- (NSString *)sortingDictionaryWithdic:(NSDictionary *)dic {
    
    NSMutableArray *array = @[].mutableCopy;
    
    for (NSInteger index = 0; index < dic.allKeys.count; index ++) {
        
        [array addObject:[NSString stringWithFormat:@"%@=%@",dic.allKeys[index],dic.allValues[index]]];
    }
    
    NSArray *resultArray = [array sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        /*
         排序结果
         NSComparisonResult resuest = [obj1 compare:obj2];为从小到大,即升序;
         NSComparisonResult resuest = [obj2 compare:obj1];为从大到小,即降序;
         注意:compare方法是区分大小写的,即按照ASCII排序
         */
        //排序操作
        NSComparisonResult resuest = [obj1 compare:obj2];
        
        return resuest;
    }];
    
    ALLog(@"resultArray:%@",resultArray);
    
    NSString *resultString = @"";
    
    for (NSInteger index = 0; index < resultArray.count; index ++) {
        
        if (index == 0) {
            
            resultString = [NSString stringWithFormat:@"%@",resultArray[index]];
            
            continue;
        }
        
        resultString = [NSString stringWithFormat:@"%@&%@",resultString,resultArray[index]];
    }
    
    resultString = [resultString stringByAppendingString:@"&buXiNjie2017!"];
    resultString = [NSString md5:resultString];
    
    return resultString;
}
 
#pragma mark --- 跳转到商品过度页 ---
- (void)jumpGoodsSplash:(NSString *)taobaoGoodsID {
    
    GoodDeTrViewController *goodsDetailVC = [[GoodDeTrViewController alloc]init];
    
    goodsDetailVC.hidesBottomBarWhenPushed = YES;
    goodsDetailVC.goodsID = taobaoGoodsID;
    
    [weexInstance.viewController.navigationController pushViewController:goodsDetailVC animated:YES];
}
 
#pragma mark --- 跳转原有商品详情 ---
- (void)jumpGoodsDetail:(NSString *)goodsID {
    
    SureWebViewController *webView=[[SureWebViewController alloc] init];
    
    [webView backClicked:^(NSString *string) {
        
    }];
    
    webView.goodsId = goodsID;
    webView.canDownRefresh = YES;
    webView.isGoodsDetail = YES;
    webView.hidesBottomBarWhenPushed = YES;
    
    [weexInstance.viewController.navigationController pushViewController:webView animated:YES];
}
 
#pragma mark --- 跳跳转网页 ---
- (void)jumpWeb:(NSString *)url {
    
    ShonpingShareViewController *shopVC = [[ShonpingShareViewController alloc]init];
    shopVC.urlString = url;
    shopVC.hidesBottomBarWhenPushed=YES;
    [weexInstance.viewController.navigationController pushViewController:shopVC animated:YES];
    
}
 
#pragma mark --- 分享 ---
- (void)share:(NSString *)type {
    
}
 
#pragma mark --- 借结束当前页面 ---
- (void)finishPage {
    
    [weexInstance.viewController.navigationController popViewControllerAnimated:YES];
}
 
@end