KSOrderManager.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // KSOrderManager.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/4/24.
  6. //
  7. #import "KSOrderManager.h"
  8. #import <AlipaySDK/AlipaySDK.h>
  9. #import "WXApi.h"
  10. @implementation KSOrderManager
  11. + (void)dealWithAliOrder:(NSString *)infoMessage {
  12. NSURL *url = [NSURL URLWithString:infoMessage];
  13. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  14. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  15. if (success) { // 跳转成功
  16. NSLog(@"success");
  17. [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"success"];
  18. }
  19. else { // 未跳转成功
  20. NSLog(@"---cancel---");
  21. [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"cancel"];
  22. }
  23. }];
  24. }
  25. else {
  26. // 未安装
  27. [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"fail"];
  28. NSLog(@"无法打开该链接---- %@----", infoMessage);
  29. }
  30. }
  31. + (void)dealWithAliSDK:(NSString *)infoMessage {
  32. if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipays://"]]) {
  33. [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"fail"];
  34. return;
  35. }
  36. else {
  37. [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"success"];
  38. }
  39. NSString *appScheme = @"ColexiuStudent";
  40. [[AlipaySDK defaultService] payOrder:infoMessage fromScheme:appScheme callback:^(NSDictionary *resultDic) {
  41. }];
  42. }
  43. + (void)dealWithWXSDK:(NSString *)infoMessage {
  44. if (![WXApi isWXAppInstalled]) {
  45. [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"fail"];
  46. return;
  47. }
  48. NSDictionary *infoDic = [self convertJsonStringToNSDictionary:infoMessage];
  49. PayReq *request = [[PayReq alloc] init];
  50. request.partnerId = [infoDic stringValueForKey:@"partnerid"];
  51. request.prepayId = [infoDic stringValueForKey:@"prepayid"];
  52. request.package = [infoDic stringValueForKey:@"packageValue"];
  53. request.nonceStr = [infoDic stringValueForKey:@"noncestr"];
  54. request.timeStamp = (UInt32)[infoDic integerValueForKey:@"timestamp"];
  55. request.sign = [infoDic stringValueForKey:@"sign"];
  56. [WXApi sendReq:request completion:^(BOOL success) {
  57. if (success) {
  58. [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"success"];
  59. }
  60. else {
  61. [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"fail"];
  62. }
  63. }];
  64. }
  65. + (NSDictionary *)convertJsonStringToNSDictionary:(NSString *)jsonString {
  66. if (jsonString == nil) {
  67. return nil;
  68. }
  69. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  70. NSError *error;
  71. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
  72. if (error) {
  73. NSLog(@"jsonString解析失败:%@", error);
  74. return nil;
  75. }
  76. return json;
  77. }
  78. @end