JXQRCodeViewController.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //
  2. // JXQRCodeViewController.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 17/9/14.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "JXQRCodeViewController.h"
  9. #import "QRImage.h"
  10. #import "JXRelayVC.h"
  11. @interface JXQRCodeViewController ()
  12. @property (nonatomic, strong) UIImageView * qrImageView;
  13. @property (nonatomic, strong) UIButton * saveButton;
  14. @property (nonatomic, strong) UIView *baseView;
  15. @end
  16. @implementation JXQRCodeViewController
  17. -(instancetype)init{
  18. if (self = [super init]) {
  19. self.heightHeader = JX_SCREEN_TOP;
  20. self.heightFooter = 0;
  21. self.title = Localized(@"JXQR_QRImage");
  22. self.isGotoBack = YES;
  23. }
  24. return self;
  25. }
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self createHeadAndFoot];
  29. self.tableBody.backgroundColor = HEXCOLOR(0xF2F2F2);
  30. [self.tableHeader addSubview:self.saveButton];
  31. // NSMutableDictionary * qrDict = [NSMutableDictionary dictionary];
  32. NSMutableString * qrStr = [NSMutableString stringWithFormat:@"%@?action=",g_config.website];
  33. if(self.type == QRUserType)
  34. [qrStr appendString:@"user"];
  35. // [qrDict setObject:@"user" forKey:@"action"];
  36. else if(self.type == QRGroupType)
  37. [qrStr appendString:@"group"];
  38. // [qrDict setObject:@"group" forKey:@"action"];
  39. if(self.account != nil)
  40. [qrStr appendFormat:@"&shikuId=%@",self.account];
  41. // [qrDict setObject:self.userId forKey:@"shiku"];
  42. if (self.type == QRAliPayType) {
  43. qrStr = self.qrString.mutableCopy;
  44. }
  45. // = [[[SBJsonWriter alloc] init] stringWithObject:qrDict];
  46. UIImageView *imageView = [[UIImageView alloc] init];
  47. if (self.type == QRGroupType) {
  48. // NSString *groupImagePath = [NSString stringWithFormat:@"%@%@/%@.%@",NSTemporaryDirectory(),g_myself.userId,self.userId,@"jpg"];
  49. // if (groupImagePath && [[NSFileManager defaultManager] fileExistsAtPath:groupImagePath]) {
  50. // imageView.image = [UIImage imageWithContentsOfFile:groupImagePath];
  51. // }else{
  52. // [roomData roomHeadImageRoomId:self.userId toView:imageView];
  53. // }
  54. [g_server getRoomHeadImageSmall:self.roomJId roomId:self.userId imageView:imageView];
  55. }else if (self.type == QRAliPayType || self.type == QRWXPayType){
  56. if (self.type == QRAliPayType) {
  57. imageView.image = [UIImage imageNamed:@"aliPay_logo"];
  58. }else {
  59. imageView.image = [UIImage imageNamed:@"weixin_logo"];
  60. }
  61. }else{
  62. [g_server getHeadImageLarge:self.userId userName:self.nickName imageView:imageView];
  63. }
  64. self.baseView = [[UIView alloc] initWithFrame:CGRectMake(15, 15, JX_SCREEN_WIDTH-30, 433)];
  65. self.baseView.backgroundColor = [UIColor whiteColor];
  66. [self.tableBody addSubview:self.baseView];
  67. UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 60, 60)];
  68. icon.image = imageView.image;
  69. icon.layer.cornerRadius = 30;
  70. icon.layer.masksToBounds = YES;
  71. [self.baseView addSubview:icon];
  72. CGSize size = [self.nickName sizeWithAttributes:@{NSFontAttributeName:SYSFONT(17)}];
  73. UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(icon.frame)+15, 41, size.width, size.height)];
  74. name.text = self.nickName;
  75. [self.baseView addSubview:name];
  76. UIImage * qrImage = [QRImage qrImageForString:qrStr imageSize:300 logoImage:imageView.image logoImageSize:70];
  77. _qrImageView = [[UIImageView alloc] initWithFrame:CGRectMake(39, CGRectGetMaxY(icon.frame)+33, self.baseView.frame.size.width-39*2, self.baseView.frame.size.width-39*2)];
  78. _qrImageView.image = qrImage;
  79. [self.baseView addSubview:_qrImageView];
  80. NSString *tintStr;
  81. if (self.type == QRUserType) {
  82. tintStr = @"扫一扫上面的二维码图案,添加我为好友";
  83. UIImageView *sex = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame)+15, 0, 14, 14)];
  84. sex.image = [UIImage imageNamed:@""];
  85. [self.baseView addSubview:sex];
  86. sex.center = CGPointMake(sex.frame.origin.x, name.center.y);
  87. if ([self.sex intValue] == 0) {// 女
  88. sex.image = [UIImage imageNamed:@"basic_famale"];
  89. }else {// 男
  90. sex.image = [UIImage imageNamed:@"basic_male"];
  91. }
  92. }else if (self.type == QRAliPayType || self.type == QRWXPayType){
  93. if(self.type == QRAliPayType){
  94. tintStr = @"用支付宝扫一扫上面的二维码图案,进行充值";
  95. }else {
  96. tintStr = @"用微信扫一扫上面的二维码图案,进行充值";
  97. }
  98. }else {
  99. tintStr = @"扫一扫上面的二维码图案,加入群组";
  100. }
  101. UILabel *tintLab = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_qrImageView.frame)+20, self.baseView.frame.size.width, 14)];
  102. tintLab.text = tintStr;
  103. tintLab.textAlignment = NSTextAlignmentCenter;
  104. tintLab.font = SYSFONT(14);
  105. tintLab.textColor = HEXCOLOR(0x999999);
  106. [self.baseView addSubview:tintLab];
  107. CGFloat w = (JX_SCREEN_WIDTH-15*3)/2;
  108. UIButton *save = [[UIButton alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.baseView.frame)+30, w, 40)];
  109. [save setTitle:@"保存到手机" forState:UIControlStateNormal];
  110. save.layer.cornerRadius = 7.f;
  111. save.layer.masksToBounds = YES;
  112. save.backgroundColor = [UIColor whiteColor];
  113. [save.titleLabel setFont:SYSFONT(16)];
  114. [save setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  115. [save addTarget:self action:@selector(saveButtonAction) forControlEvents:UIControlEventTouchUpInside];
  116. [self.tableBody addSubview:save];
  117. UIButton *share = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(save.frame)+15, CGRectGetMaxY(self.baseView.frame)+30, w, 40)];
  118. [share setTitle:@"分享" forState:UIControlStateNormal];
  119. share.layer.cornerRadius = 7.f;
  120. share.layer.masksToBounds = YES;
  121. share.backgroundColor = THEMECOLOR;
  122. [share.titleLabel setFont:SYSFONT(16)];
  123. [share addTarget:self action:@selector(shareButtonAction) forControlEvents:UIControlEventTouchUpInside];
  124. [self.tableBody addSubview:share];
  125. if (self.amount) {
  126. [g_App showAlert:[NSString stringWithFormat:@"温馨提示\n支付时请输入与本次支付金额相同的金额(%@元),如不相同,会充值失败,本平台概不负责!!!",self.amount]];
  127. }
  128. }
  129. -(void)saveButtonAction{
  130. UIImage * image = [UIImage imageWithView:self.baseView];
  131. [self saveToLibary:image];
  132. }
  133. - (void)shareButtonAction {
  134. NSString *name = @"jpg";
  135. NSString *file = [FileInfo getUUIDFileName:name];
  136. [g_server saveImageToFile:[UIImage imageWithView:self.baseView] file:file isOriginal:YES];
  137. [g_server uploadFile:file validTime:nil messageId:nil toView:self];
  138. }
  139. -(void)saveToLibary:(UIImage *)image{
  140. UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
  141. }
  142. -(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
  143. if (!error) {
  144. [g_server showMsg:Localized(@"JX_SaveSuessed") delay:1.5f];
  145. }else{
  146. [g_App showAlert:error.description];
  147. }
  148. }
  149. - (void)didReceiveMemoryWarning {
  150. [super didReceiveMemoryWarning];
  151. // Dispose of any resources that can be recreated.
  152. }
  153. -(UIButton *)saveButton{
  154. if(!_saveButton){
  155. _saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
  156. _saveButton.frame = CGRectMake(JX_SCREEN_WIDTH-15-18, JX_SCREEN_TOP - 15-18, 18, 18);
  157. [_saveButton setImage:[UIImage imageNamed:@"saveLibary_black"] forState:UIControlStateNormal];
  158. [_saveButton addTarget:self action:@selector(saveButtonAction) forControlEvents:UIControlEventTouchUpInside];
  159. }
  160. return _saveButton;
  161. }
  162. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  163. [_wait stop];
  164. if ([aDownload.action isEqualToString:act_UploadFile]) {
  165. NSDictionary* p = nil;
  166. if([(NSArray *)[dict objectForKey:@"images"] count]>0)
  167. p = [[dict objectForKey:@"images"] objectAtIndex:0];
  168. JXMessageObject *msg = [[JXMessageObject alloc] init];
  169. msg.fromUserId = MY_USER_ID;
  170. msg.fromUserName = MY_USER_NAME;
  171. msg.type = [NSNumber numberWithInt:kWCMessageTypeImage];
  172. msg.content = [p objectForKey:@"oUrl"];
  173. msg.timeSend = [NSDate date];
  174. msg.isSend = [NSNumber numberWithInt:transfer_status_ing];
  175. msg.isRead = [NSNumber numberWithBool:NO];
  176. msg.isUpload = [NSNumber numberWithBool:NO];
  177. [msg setMsgId];
  178. JXRelayVC *vc = [[JXRelayVC alloc] init];
  179. vc.relayMsgArray = [NSMutableArray arrayWithObject:msg];
  180. [g_navigation pushViewController:vc animated:YES];
  181. }
  182. }
  183. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  184. [_wait stop];
  185. return show_error;
  186. }
  187. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  188. [_wait stop];
  189. return show_error;
  190. }
  191. -(void) didServerConnectStart:(JXConnection*)aDownload{
  192. [_wait start];
  193. }
  194. @end