FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Controllers/EAPayViewController.m at master · badstreams/Coding-iOS · GitHub
badstreams
/
Coding-iOS
Public
forked from
coding/Coding-iOS
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
EAPayViewController.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
111 lines (93 loc) · 3.12 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
EAPayViewController.m
Copy path
File metadata and controls
111 lines (93 loc) · 3.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
//
EAPayViewController.m
//
Coding_iOS
//
//
Created by Easeeeeeeeee on 2017/11/29.
//
Copyright © 2017年 Coding. All rights reserved.
//
#
import
"
EAPayViewController.h
"
#
import
<
AlipaySDK/AlipaySDK.h
>
#
import
<
UMengUShare/WXApi.h
>
#
import
<
UMengUShare/WXApiObject.h
>
#
import
"
Coding_NetAPIManager.h
"
@interface
EAPayViewController
()
@property
(
assign
,
nonatomic
)
NSInteger
payMethod;
//
0 alipay, 1 wechat
@property
(
strong
,
nonatomic
)
NSDictionary
*payDict;
@end
@implementation
EAPayViewController
- (
void
)
viewDidLoad
{
[
super
viewDidLoad
];
//
Do any additional setup after loading the view from its nib.
self.
title
=
@"
支付
"
;
self.
payMethod
=
0
;
}
- (
IBAction
)
methodBtnClicked
:
(UIButton *)
sender
{
self.
payMethod
= sender.
tag
;
if
(self.
payMethod
==
1
&& ![
self
p_canOpenWeiXin
]){
[
NSObject
showHudTipStr:
@"
您还没有安装「微信」
"
];
return
;
}
[
NSObject
showHUDQueryStr:
@"
请稍等...
"
];
__weak
typeof
(self) weakSelf = self;
[[Coding_NetAPIManager
sharedManager
]
request_shop_payOrder:
_shopOrder.orderNo
method:
_payMethod ==
0
?
@"
Alipay
"
:
@"
Weixin
"
andBlock:
^(
NSDictionary
*payDict,
NSError
*error) {
[
NSObject
hideHUDQuery
];
weakSelf.
payDict
= payDict;
if
(weakSelf.
payMethod
==
0
) {
[weakSelf
aliPay
];
}
else
{
[weakSelf
weixinPay
];
}
}];
}
- (
void
)
aliPay
{
__weak
typeof
(self) weakSelf = self;
[[AlipaySDK
defaultService
]
payOrder:
_payDict[
@"
url
"
]
fromScheme:
kCodingAppScheme
callback:
^(
NSDictionary
*resultDic) {
[weakSelf
handleAliResult:
resultDic];
}];
}
- (
void
)
weixinPay
{
PayReq *req = [PayReq
new
];
NSDictionary
*resultDict = _payDict;
req.
partnerId
= resultDict[
@"
partnerId
"
];
req.
prepayId
= resultDict[
@"
prepayId
"
];
req.
nonceStr
= resultDict[
@"
nonceStr
"
];
req.
timeStamp
= [resultDict[
@"
timestamp
"
]
intValue
];
req.
package
= resultDict[
@"
package
"
];
req.
sign
= resultDict[
@"
sign
"
];
[WXApi
sendReq:
req];
}
- (
void
)
handleAliResult
:
(
NSDictionary
*)
resultDic
{
DebugLog
(
@"
handleAliResult:
%@
"
, resultDic);
BOOL
isPaySuccess =
NO
;
if
(_payMethod ==
0
) {
isPaySuccess = ([resultDic[
@"
resultStatus
"
]
integerValue
] ==
9000
);
}
else
{
NSInteger
resultCode = [resultDic[
@"
ret
"
]
intValue
];
isPaySuccess = (resultCode ==
0
);
}
[
NSObject
showHudTipStr:
isPaySuccess?
@"
支付成功
"
:
@"
支付失败
"
];
if
(isPaySuccess) {
[
self
.navigationController
popViewControllerAnimated:
YES
];
}
}
- (
void
)
handlePayURL
:
(
NSURL
*)
url
{
if
(_payMethod ==
0
) {
__weak
typeof
(self) weakSelf = self;
[[AlipaySDK
defaultService
]
processOrderWithPaymentResult:
url
standbyCallback:
^(
NSDictionary
*resultDic) {
[weakSelf
handleAliResult:
resultDic];
}];
}
else
{
[
self
handleAliResult:
[url
queryParams
]];
}
}
#
pragma mark
- app url
- (
BOOL
)
p_canOpenWeiXin
{
return
[
self
p_canOpen:
@"
weixin://
"
];
}
- (
BOOL
)
p_canOpenAlipay
{
return
[
self
p_canOpen:
@"
alipay://
"
];
}
- (
BOOL
)
p_canOpen
:
(
NSString
*)
url
{
return
[[UIApplication
sharedApplication
]
canOpenURL:
[
NSURL
URLWithString:
url]];
}
@end
Back
|
FazBrowse Home
|
New Git URL