AliPay.mm 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // AliPay.m
  3. // UnityAliPay
  4. //
  5. // Created by Fenix Wang on 2017/8/14.
  6. // Copyright © 2017年 Fenix Wang. All rights reserved.
  7. //
  8. #import "AliPay.h"
  9. #import <AlipaySDK/AlipaySDK.h>
  10. @implementation AliPay
  11. - (void)payResult:(NSString *)gameObj resultDic:(NSDictionary *)resultDic
  12. {
  13. NSLog(@"reslut = %@", resultDic);
  14. NSString *method = @"OnPayResult";
  15. NSString *resultStatus = [resultDic objectForKey:@"resultStatus"];
  16. NSString *result = [resultDic objectForKey:@"result"];
  17. NSString *value = [NSString stringWithFormat:@"%@|%@", resultStatus, result];
  18. UnitySendMessage([gameObj UTF8String], [method UTF8String], [value UTF8String]);
  19. }
  20. @end
  21. extern "C" {
  22. void UnitySendMessage(const char* obj, const char* method, const char* msg);
  23. void aliPay(const char* orderInfo, const char* gameObjectName)
  24. {
  25. NSString *orderInfoStr = [NSString stringWithUTF8String:orderInfo];
  26. NSString *gameObjectNameStr = [NSString stringWithUTF8String:gameObjectName];
  27. [[AlipaySDK defaultService] payOrder:orderInfoStr fromScheme:@"MyLovelyGarden" callback:^(NSDictionary *resultDic) {
  28. [[[AliPay alloc] init] payResult:gameObjectNameStr resultDic:resultDic];
  29. }];
  30. }
  31. }