JXCashWithDrawViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. //
  2. // JXCashWithDrawViewController.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 17/10/27.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "JXCashWithDrawViewController.h"
  9. #import "UIImage+Color.h"
  10. #import "WXApi.h"
  11. #import "WXApiManager.h"
  12. #import "JXVerifyPayVC.h"
  13. #import "JXPayPasswordVC.h"
  14. #import <AlipaySDK/AlipaySDK.h>
  15. #define drawMarginX 20
  16. #define bgWidth JX_SCREEN_WIDTH-15*2
  17. #define drawHei 60
  18. @interface JXCashWithDrawViewController ()<UITextFieldDelegate>
  19. @property (nonatomic, strong) UIButton * helpButton;
  20. @property (nonatomic, strong) UIControl * hideControl;
  21. @property (nonatomic, strong) UIControl * bgView;
  22. @property (nonatomic, strong) UIView * targetView;
  23. @property (nonatomic, strong) UIView * inputView;
  24. @property (nonatomic, strong) UIView * balanceView;
  25. @property (nonatomic, strong) UIButton * cardButton;
  26. @property (nonatomic, strong) UITextField * countTextField;
  27. @property (nonatomic, strong) UILabel * balanceLabel;
  28. @property (nonatomic, strong) UILabel * jxCoinL;
  29. @property (nonatomic, strong) UIButton * drawAllBtn;
  30. @property (nonatomic, strong) UIButton * withdrawalsBtn;
  31. @property (nonatomic, strong) UIButton * aliwithdrawalsBtn;
  32. @property (nonatomic, strong) ATMHud *loading;
  33. @property (nonatomic, strong) JXVerifyPayVC *verVC;
  34. @property (nonatomic, strong) NSString *payPassword;
  35. @property (nonatomic, assign) BOOL isAlipay;
  36. @property (nonatomic, strong) NSString *aliUserId;
  37. @end
  38. @implementation JXCashWithDrawViewController
  39. -(instancetype)init{
  40. if (self = [super init]) {
  41. self.heightHeader = JX_SCREEN_TOP;
  42. self.heightFooter = 0;
  43. self.isGotoBack = YES;
  44. self.title = Localized(@"JXMoney_withdrawals");
  45. }
  46. return self;
  47. }
  48. - (void)viewDidLoad {
  49. [super viewDidLoad];
  50. self.view.frame = CGRectMake(JX_SCREEN_WIDTH, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  51. [self createHeadAndFoot];
  52. self.tableBody.backgroundColor = HEXCOLOR(0xF2F2F2);
  53. // [self.tableHeader addSubview:self.helpButton];
  54. [self.tableBody addSubview:self.hideControl];
  55. [self.tableBody addSubview:self.bgView];
  56. // [self.bgView addSubview:self.targetView];
  57. [self.bgView addSubview:self.inputView];
  58. [self.bgView addSubview:self.balanceView];
  59. self.bgView.frame = CGRectMake(15, 20, bgWidth, CGRectGetMaxY(_balanceView.frame));
  60. _loading = [[ATMHud alloc] init];
  61. [g_notify addObserver:self selector:@selector(authRespNotification:) name:kWxSendAuthRespNotification object:nil];
  62. long time = (long)[[NSDate date] timeIntervalSince1970];
  63. time = (time *1000 + g_server.timeDifference);
  64. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  65. [g_server getMyCoinsss:salt andToView:self];
  66. }
  67. -(UIButton *)helpButton{
  68. if(!_helpButton){
  69. _helpButton = [UIButton buttonWithType:UIButtonTypeCustom];
  70. _helpButton.frame = CGRectMake(JX_SCREEN_WIDTH -15-18, JX_SCREEN_TOP -15-18, 18, 18);
  71. NSString *image = THESIMPLESTYLE ? @"im_003_more_button_black" : @"im_003_more_button_normal";
  72. [_helpButton setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
  73. [_helpButton setImage:[UIImage imageNamed:image] forState:UIControlStateHighlighted];
  74. [_helpButton addTarget:self action:@selector(helpButtonAction) forControlEvents:UIControlEventTouchUpInside];
  75. }
  76. return _helpButton;
  77. }
  78. -(UIControl *)hideControl{
  79. if (!_hideControl) {
  80. _hideControl = [[UIControl alloc] init];
  81. _hideControl.frame = self.tableBody.bounds;
  82. [_hideControl addTarget:self action:@selector(hideControlAction) forControlEvents:UIControlEventTouchUpInside];
  83. }
  84. return _hideControl;
  85. }
  86. -(UIView *)bgView{
  87. if (!_bgView) {
  88. _bgView = [[UIControl alloc] init];
  89. _bgView.frame = CGRectMake(15, 20, bgWidth, 400);
  90. _bgView.backgroundColor = [UIColor whiteColor];
  91. _bgView.layer.cornerRadius = 5;
  92. _bgView.clipsToBounds = YES;
  93. }
  94. return _bgView;
  95. }
  96. -(UIView *)targetView{
  97. if (!_targetView) {
  98. _targetView = [[UIView alloc] init];
  99. _targetView.frame = CGRectMake(0, 0, bgWidth, drawHei);
  100. _targetView.backgroundColor = [UIColor colorWithWhite:0.97 alpha:1];
  101. UILabel * targetLabel = [UIFactory createLabelWith:CGRectMake(drawMarginX, 0, 120, drawHei) text:Localized(@"JXMoney_withDrawalsTarget")];
  102. [_targetView addSubview:targetLabel];
  103. CGRect btnFrame = CGRectMake(CGRectGetMaxX(targetLabel.frame)+20, 0, bgWidth-CGRectGetMaxX(targetLabel.frame)-20-drawMarginX, drawHei);
  104. _cardButton = [UIFactory createButtonWithRect:btnFrame title:@"微信号(8868)" titleFont:g_factory.font15 titleColor:HEXCOLOR(0x576b95) normal:nil selected:nil selector:@selector(cardButtonAction:) target:self];
  105. [_targetView addSubview:_cardButton];
  106. }
  107. return _targetView;
  108. }
  109. -(UIView *)inputView{
  110. if (!_inputView) {
  111. _inputView = [[UIView alloc] init];
  112. _inputView.frame = CGRectMake(0, 0, bgWidth, 126);
  113. _inputView.backgroundColor = [UIColor whiteColor];
  114. UILabel * cashTitle = [UIFactory createLabelWith:CGRectMake(drawMarginX, drawMarginX, 120, 15) text:Localized(@"JXMoney_withDAmount")];
  115. cashTitle.font = SYSFONT(15);
  116. cashTitle.textColor = HEXCOLOR(0x999999);
  117. [_inputView addSubview:cashTitle];
  118. UILabel * rmbLabel = [UIFactory createLabelWith:CGRectMake(drawMarginX, CGRectGetMaxY(cashTitle.frame)+36, 18, 30) text:@"¥"];
  119. rmbLabel.font = SYSFONT(30);
  120. rmbLabel.textAlignment = NSTextAlignmentLeft;
  121. [_inputView addSubview:rmbLabel];
  122. _countTextField = [UIFactory createTextFieldWithRect:CGRectMake(CGRectGetMaxX(rmbLabel.frame)+15, CGRectGetMaxY(cashTitle.frame)+31, bgWidth-CGRectGetMaxX(rmbLabel.frame)-drawMarginX-15, 40) keyboardType:UIKeyboardTypeDecimalPad secure:NO placeholder:nil font:[UIFont boldSystemFontOfSize:40] color:[UIColor blackColor] delegate:self];
  123. _countTextField.borderStyle = UITextBorderStyleNone;
  124. [_inputView addSubview:_countTextField];
  125. UIView * line = [[UIView alloc] init];
  126. line.frame = CGRectMake(drawMarginX, CGRectGetMaxY(_countTextField.frame)+15, bgWidth-drawMarginX*2, LINE_WH);
  127. line.backgroundColor = THE_LINE_COLOR;
  128. [_inputView addSubview:line];
  129. }
  130. return _inputView;
  131. }
  132. -(UIView *)balanceView{
  133. if (!_balanceView) {
  134. _balanceView = [[UIView alloc] init];
  135. _balanceView.frame = CGRectMake(0, CGRectGetMaxY(_inputView.frame), bgWidth, 216);
  136. _balanceView.backgroundColor = [UIColor whiteColor];
  137. NSString * moneyStr = [NSString stringWithFormat:@"%@¥%.2f,",Localized(@"JXMoney_blance"),g_App.myMoney];
  138. _balanceLabel = [UIFactory createLabelWith:CGRectZero text:moneyStr font:g_factory.font14 textColor:[UIColor lightGrayColor] backgroundColor:nil];
  139. CGFloat blanceWidth = [moneyStr sizeWithAttributes:@{NSFontAttributeName:_balanceLabel.font}].width;
  140. _balanceLabel.frame = CGRectMake(drawMarginX, drawMarginX, blanceWidth, 14);
  141. [_balanceView addSubview:_balanceLabel];
  142. NSString * moneyStr2 = [NSString stringWithFormat:@"即信币"];
  143. _jxCoinL = [UIFactory createLabelWith:CGRectZero text:moneyStr2 font:g_factory.font14 textColor:[UIColor lightGrayColor] backgroundColor:nil];
  144. CGFloat blanceWidthX = [moneyStr sizeWithAttributes:@{NSFontAttributeName:_balanceLabel.font}].width;
  145. _jxCoinL.frame = CGRectMake(drawMarginX, drawMarginX+19, blanceWidthX, 14);
  146. [_balanceView addSubview:_jxCoinL];
  147. _drawAllBtn = [UIFactory createButtonWithRect:CGRectZero title:Localized(@"JXMoney_withDAll") titleFont:_balanceLabel.font titleColor:HEXCOLOR(0x576b95) normal:nil selected:nil selector:@selector(drawAllBtnAction) target:self];
  148. CGFloat drawWidth = [_drawAllBtn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:_drawAllBtn.titleLabel.font}].width;
  149. _drawAllBtn.frame = CGRectMake(CGRectGetMaxX(_balanceLabel.frame)+10, CGRectGetMinY(_balanceLabel.frame), drawWidth, 14);
  150. [_balanceView addSubview:_drawAllBtn];
  151. _withdrawalsBtn = [UIFactory createButtonWithRect:CGRectZero title:Localized(@"JXMoney_wechatWithdrawals") titleFont:g_factory.font16 titleColor:[UIColor whiteColor] normal:nil selected:nil selector:@selector(withdrawalsBtnAction:) target:self];
  152. _withdrawalsBtn.tag = 1000;
  153. _withdrawalsBtn.frame = CGRectMake(drawMarginX, CGRectGetMaxY(_balanceLabel.frame)+30, bgWidth-drawMarginX*2, 40);
  154. [_withdrawalsBtn setImage:[UIImage imageNamed:@"withdrawal_weixin"] forState:UIControlStateNormal];
  155. [_withdrawalsBtn setBackgroundImage:[UIImage createImageWithColor:HEXCOLOR(0x22CC06)] forState:UIControlStateNormal];
  156. // [_withdrawalsBtn setBackgroundImage:[UIImage createImageWithColor:HEXCOLOR(0x22CC06)] forState:UIControlStateDisabled];
  157. _withdrawalsBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  158. _withdrawalsBtn.layer.cornerRadius = 7;
  159. _withdrawalsBtn.clipsToBounds = YES;
  160. [_balanceView addSubview:_withdrawalsBtn];
  161. _aliwithdrawalsBtn = [UIFactory createButtonWithRect:CGRectZero title:Localized(@"JXMoney_Aliwithdrawals") titleFont:g_factory.font16 titleColor:[UIColor whiteColor] normal:nil selected:nil selector:@selector(withdrawalsBtnAction:) target:self];
  162. _aliwithdrawalsBtn.tag = 1011;
  163. _aliwithdrawalsBtn.frame = CGRectMake(drawMarginX, CGRectGetMaxY(_withdrawalsBtn.frame)+20, bgWidth-drawMarginX*2, 40);
  164. [_aliwithdrawalsBtn setImage:[UIImage imageNamed:@"withdrawal_aliPay"] forState:UIControlStateNormal];
  165. [_aliwithdrawalsBtn setBackgroundImage:[UIImage createImageWithColor:HEXCOLOR(0x3E98FF)] forState:UIControlStateNormal];
  166. // [_aliwithdrawalsBtn setBackgroundImage:[UIImage createImageWithColor:HEXCOLOR(0x3E98FF)] forState:UIControlStateDisabled];
  167. _aliwithdrawalsBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  168. _aliwithdrawalsBtn.layer.cornerRadius = 7;
  169. _aliwithdrawalsBtn.clipsToBounds = YES;
  170. [_balanceView addSubview:_aliwithdrawalsBtn];
  171. UILabel *noticeLabel = [UIFactory createLabelWith:CGRectMake(drawMarginX, CGRectGetMaxY(_aliwithdrawalsBtn.frame)+20, bgWidth-drawMarginX*2, 13) text:Localized(@"JXMoney_withDNotice") font:g_factory.font13 textColor:HEXCOLOR(0x999999) backgroundColor:nil];
  172. noticeLabel.textAlignment = NSTextAlignmentCenter;
  173. [_balanceView addSubview:noticeLabel];
  174. }
  175. return _balanceView;
  176. }
  177. - (void)didReceiveMemoryWarning {
  178. [super didReceiveMemoryWarning];
  179. // Dispose of any resources that can be recreated.
  180. }
  181. /*
  182. #pragma mark - Navigation
  183. // In a storyboard-based application, you will often want to do a little preparation before navigation
  184. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  185. // Get the new view controller using [segue destinationViewController].
  186. // Pass the selected object to the new view controller.
  187. }
  188. */
  189. #pragma mark TextField Delegate
  190. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  191. if (textField == _countTextField) {
  192. NSString *toString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  193. if (toString.length > 0) {
  194. NSString *stringRegex = @"(([0]|(0[.]\\d{0,2}))|([1-9]\\d{0,4}(([.]\\d{0,2})?)))?";
  195. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", stringRegex];
  196. if (![predicate evaluateWithObject:toString]) {
  197. return NO;
  198. }
  199. }
  200. }
  201. return YES;
  202. }
  203. #pragma mark Action
  204. -(void)cardButtonAction:(UIButton *)button{
  205. }
  206. -(void)drawAllBtnAction{
  207. NSString * allMoney = [NSString stringWithFormat:@"%.2f",g_App.myMoney];
  208. _countTextField.text = allMoney;
  209. }
  210. -(void)withdrawalsBtnAction:(UIButton *)button{
  211. if ([_countTextField.text doubleValue] < 0.5) {
  212. [g_App showAlert:Localized(@"JX_Least0.5")];
  213. return;
  214. }
  215. // if ([_countTextField.text doubleValue] > g_App.myMoney) {
  216. // [g_App showAlert:Localized(@"CREDIT_LOW")];
  217. // return;
  218. // }
  219. if ([g_server.myself.isPayPassword boolValue]) {
  220. self.isAlipay = button.tag == 1011;
  221. self.verVC = [JXVerifyPayVC alloc];
  222. self.verVC.type = JXVerifyTypeWithdrawal;
  223. self.verVC.RMB = self.countTextField.text;
  224. self.verVC.delegate = self;
  225. self.verVC.didDismissVC = @selector(dismissVerifyPayVC);
  226. self.verVC.didVerifyPay = @selector(didVerifyPay:);
  227. self.verVC = [self.verVC init];
  228. [self.view addSubview:self.verVC.view];
  229. } else {
  230. JXPayPasswordVC *payPswVC = [JXPayPasswordVC alloc];
  231. payPswVC.type = JXPayTypeSetupPassword;
  232. payPswVC.enterType = JXEnterTypeWithdrawal;
  233. payPswVC = [payPswVC init];
  234. [g_navigation pushViewController:payPswVC animated:YES];
  235. }
  236. // // 绑定微信
  237. // SendAuthReq* req = [[SendAuthReq alloc] init];
  238. // req.scope = @"snsapi_message,snsapi_userinfo,snsapi_friend,snsapi_contact";
  239. // NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  240. // // app名称
  241. // NSString *titleStr = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  242. // req.state = titleStr;
  243. // req.openID = AppleId;
  244. //
  245. // [WXApi sendAuthReq:req
  246. // viewController:self
  247. // delegate:[WXApiManager sharedManager]];
  248. }
  249. - (void)didVerifyPay:(NSString *)sender {
  250. self.payPassword = [NSString stringWithString:sender];
  251. if (self.isAlipay) {
  252. [g_server getAliPayAuthInfoToView:self];
  253. }else {
  254. // 绑定微信
  255. SendAuthReq* req = [[SendAuthReq alloc] init];
  256. req.scope = @"snsapi_message,snsapi_userinfo,snsapi_friend,snsapi_contact";
  257. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  258. // app名称
  259. NSString *titleStr = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  260. req.state = titleStr;
  261. req.openID = g_App.config.appleId;
  262. [WXApi sendAuthReq:req
  263. viewController:self
  264. delegate:[WXApiManager sharedManager]];
  265. }
  266. }
  267. - (void)dismissVerifyPayVC {
  268. [self.verVC.view removeFromSuperview];
  269. }
  270. - (void)authRespNotification:(NSNotification *)notif {
  271. SendAuthResp *resp = notif.object;
  272. [self getWeChatTokenThenGetUserInfoWithCode:resp.code];
  273. }
  274. // 用户绑定微信,获取openid
  275. - (void)getWeChatTokenThenGetUserInfoWithCode:(NSString *)code {
  276. // [_loading start];
  277. long time = (long)[[NSDate date] timeIntervalSince1970];
  278. time = (time *1000 + g_server.timeDifference)/1000;
  279. // 参数顺序不能变,先放key再放value
  280. NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"code",code, nil];
  281. [g_payServer payServerWithAction:act_UserBindWXCodeV1 param:arr payPassword:self.payPassword time:time toView:self];
  282. // [g_server userBindWXCodeWithCode:code toView:self];
  283. }
  284. -(void)hideControlAction{
  285. [_countTextField resignFirstResponder];
  286. }
  287. -(void)actionQuit{
  288. [_countTextField resignFirstResponder];
  289. [super actionQuit];
  290. }
  291. -(void)helpButtonAction{
  292. }
  293. - (void)alipayGetUserId:(NSNotification *)noti {
  294. long time = (long)[[NSDate date] timeIntervalSince1970];
  295. time = (time *1000 + g_server.timeDifference)/1000;
  296. // 参数顺序不能变,先放key再放value
  297. NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"aliUserId",noti.object, nil];
  298. [g_payServer payServerWithAction:act_aliPayUserIdV1 param:arr payPassword:self.payPassword time:time toView:self];
  299. // [g_server aliPayUserId:noti.object toView:self];
  300. }
  301. - (void)didServerResultSucces:(JXConnection *)aDownload dict:(NSDictionary *)dict array:(NSArray *)array1{
  302. // [_wait stop];
  303. if ([aDownload.action isEqualToString:act_GetMyCoin]) {
  304. NSString * moneyStr = [NSString stringWithFormat:@"即信币:%@",dict[@"coin"]];
  305. _jxCoinL.text= moneyStr;
  306. }
  307. if ([aDownload.action isEqualToString:act_UserBindWXCode] || [aDownload.action isEqualToString:act_UserBindWXCodeV1]) {
  308. // NSString *amount = [NSString stringWithFormat:@"%d",(int)([_countTextField.text doubleValue] * 100)];
  309. NSString *amount = _countTextField.text;
  310. long time = (long)[[NSDate date] timeIntervalSince1970];
  311. time = (time *1000 + g_server.timeDifference)/1000;
  312. NSString *secret = [self secretEncryption:dict[@"openid"] amount:amount time:time payPassword:self.payPassword];
  313. // 参数顺序不能变,先放key再放value
  314. NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"amount",amount, nil];
  315. [g_payServer payServerWithAction:act_TransferWXPayV1 param:arr payPassword:self.payPassword time:time toView:self];
  316. // [g_server transferWXPayWithAmount:amount secret:secret time:[NSNumber numberWithLong:time] toView:self];
  317. }else if ([aDownload.action isEqualToString:act_TransferWXPay] || [aDownload.action isEqualToString:act_TransferWXPayV1]) {
  318. [_loading stop];
  319. [self dismissVerifyPayVC]; // 销毁支付密码界面
  320. [g_App showAlert:Localized(@"JX_WithdrawalSuccess")];
  321. _countTextField.text = nil;
  322. [g_server getUserMoenyToView:self];
  323. }
  324. if ([aDownload.action isEqualToString:act_getUserMoeny]) {
  325. g_App.myMoney = [dict[@"balance"] doubleValue];
  326. _balanceLabel.text = [NSString stringWithFormat:@"%@¥%.2f,",Localized(@"JXMoney_blance"),g_App.myMoney];
  327. [g_notify postNotificationName:kUpdateUserNotifaction object:nil];
  328. }
  329. if ([aDownload.action isEqualToString:act_aliPayUserId] || [aDownload.action isEqualToString:act_aliPayUserIdV1]) {
  330. long time = (long)[[NSDate date] timeIntervalSince1970];
  331. time = (time *1000 + g_server.timeDifference)/1000;
  332. NSString *secret = [self secretEncryption:self.aliUserId amount:_countTextField.text time:time payPassword:self.payPassword];
  333. // 参数顺序不能变,先放key再放value
  334. NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"amount",self.countTextField.text, nil];
  335. [g_payServer payServerWithAction:act_alipayTransferV1 param:arr payPassword:self.payPassword time:time toView:self];
  336. // [g_server alipayTransfer:self.countTextField.text secret:secret time:@(time) toView:self];
  337. }
  338. if ([aDownload.action isEqualToString:act_alipayTransfer] || [aDownload.action isEqualToString:act_alipayTransferV1]) {
  339. [g_server showMsg:Localized(@"JX_WithdrawalSuccess")];
  340. [g_navigation dismissViewController:self animated:YES];
  341. }
  342. if ([aDownload.action isEqualToString:act_getAliPayAuthInfo]) {
  343. NSString *aliId = [dict objectForKey:@"aliUserId"];
  344. NSString *authInfo = [dict objectForKey:@"authInfo"];
  345. if (IsStringNull(aliId)) {
  346. NSString *appScheme = @"shikuimapp";
  347. [[AlipaySDK defaultService] auth_V2WithInfo:authInfo
  348. fromScheme:appScheme
  349. callback:^(NSDictionary *resultDic) {
  350. NSLog(@"result = %@",resultDic);
  351. // 解析 auth code
  352. NSString *result = resultDic[@"result"];
  353. if (result.length>0) {
  354. NSArray *resultArr = [result componentsSeparatedByString:@"&"];
  355. for (NSString *subResult in resultArr) {
  356. if (subResult.length > 10 && [subResult hasPrefix:@"user_id="]) {
  357. self.aliUserId = [subResult substringFromIndex:8];
  358. long time = (long)[[NSDate date] timeIntervalSince1970];
  359. time = (time *1000 + g_server.timeDifference)/1000;
  360. // 参数顺序不能变,先放key再放value
  361. NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"aliUserId",self.aliUserId, nil];
  362. [g_payServer payServerWithAction:act_aliPayUserIdV1 param:arr payPassword:self.payPassword time:time toView:self];
  363. // [g_server aliPayUserId:self.aliUserId toView:self];
  364. break;
  365. }
  366. }
  367. }
  368. }];
  369. }else {
  370. long time = (long)[[NSDate date] timeIntervalSince1970];
  371. time = (time *1000 + g_server.timeDifference)/1000;
  372. NSString *secret = [self secretEncryption:aliId amount:_countTextField.text time:time payPassword:self.payPassword];
  373. // 参数顺序不能变,先放key再放value
  374. NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"amount",self.countTextField.text, nil];
  375. [g_payServer payServerWithAction:act_alipayTransferV1 param:arr payPassword:self.payPassword time:time toView:self];
  376. // [g_server alipayTransfer:self.countTextField.text secret:secret time:@(time) toView:self];
  377. }
  378. }
  379. }
  380. - (int)didServerResultFailed:(JXConnection *)aDownload dict:(NSDictionary *)dict{
  381. [_loading stop];
  382. if ([aDownload.action isEqualToString:act_alipayTransfer] || [aDownload.action isEqualToString:act_alipayTransferV1]) {
  383. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  384. [self.verVC clearUpPassword];
  385. });
  386. }
  387. return show_error;
  388. }
  389. - (int)didServerConnectError:(JXConnection *)aDownload error:(NSError *)error{
  390. [_loading stop];
  391. return hide_error;
  392. }
  393. - (NSString *)secretEncryption:(NSString *)openId amount:(NSString *)amount time:(long)time payPassword:(NSString *)payPassword {
  394. NSString *secret = [NSString string];
  395. NSMutableString *str1 = [NSMutableString string];
  396. [str1 appendString:APIKEY];
  397. [str1 appendString:openId];
  398. [str1 appendString:MY_USER_ID];
  399. NSMutableString *str2 = [NSMutableString string];
  400. [str2 appendString:g_server.access_token];
  401. [str2 appendString:amount];
  402. [str2 appendString:[NSString stringWithFormat:@"%ld",time]];
  403. str2 = [[g_server getMD5String:str2] mutableCopy];
  404. [str1 appendString:str2];
  405. NSMutableString *str3 = [NSMutableString string];
  406. str3 = [[g_server getMD5String:payPassword] mutableCopy];
  407. [str1 appendString:str3];
  408. secret = [g_server getMD5String:str1];
  409. return secret;
  410. }
  411. -(void) didServerConnectStart:(JXConnection*)aDownload{
  412. // [_wait start];
  413. }
  414. @end