1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // KSOrderManager.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2022/4/24.
- //
- #import "KSOrderManager.h"
- #import <AlipaySDK/AlipaySDK.h>
- #import "WXApi.h"
- @implementation KSOrderManager
- + (void)dealWithAliOrder:(NSString *)infoMessage {
- NSURL *url = [NSURL URLWithString:infoMessage];
- if ([[UIApplication sharedApplication] canOpenURL:url]) {
- [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
- if (success) { // 跳转成功
- NSLog(@"success");
- [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"success"];
- }
- else { // 未跳转成功
- NSLog(@"---cancel---");
- [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"cancel"];
- }
- }];
- }
- else {
- // 未安装
- [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"fail"];
- NSLog(@"无法打开该链接---- %@----", infoMessage);
- }
- }
- + (void)dealWithAliSDK:(NSString *)infoMessage {
- if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipays://"]]) {
- [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"fail"];
- return;
- }
- else {
- [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"success"];
- }
- NSString *appScheme = @"ColexiuStudent";
- [[AlipaySDK defaultService] payOrder:infoMessage fromScheme:appScheme callback:^(NSDictionary *resultDic) {
-
- }];
- }
- + (void)dealWithWXSDK:(NSString *)infoMessage {
- if (![WXApi isWXAppInstalled]) {
- [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"fail"];
- return;
- }
- NSDictionary *infoDic = [self convertJsonStringToNSDictionary:infoMessage];
- PayReq *request = [[PayReq alloc] init];
- request.partnerId = [infoDic stringValueForKey:@"partnerid"];
- request.prepayId = [infoDic stringValueForKey:@"prepayid"];
- request.package = [infoDic stringValueForKey:@"packageValue"];
- request.nonceStr = [infoDic stringValueForKey:@"noncestr"];
- request.timeStamp = (UInt32)[infoDic integerValueForKey:@"timestamp"];
- request.sign = [infoDic stringValueForKey:@"sign"];
- [WXApi sendReq:request completion:^(BOOL success) {
- if (success) {
- [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"success"];
- }
- else {
- [[NSNotificationCenter defaultCenter] postNotificationName:DEALCALLBACKNOTICIFATION object:@"fail"];
- }
- }];
- }
- + (NSDictionary *)convertJsonStringToNSDictionary:(NSString *)jsonString {
- if (jsonString == nil) {
- return nil;
- }
- NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
- NSError *error;
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
- if (error) {
- NSLog(@"jsonString解析失败:%@", error);
- return nil;
- }
- return json;
- }
- @end
|