开发索引
iOS篇

MGM Money iOS端 集成流程

导入代码
启动 Xcode,把 iOS 包中的压缩文件中以下文件拷贝到项目文件夹下,并导入到项目工程中。

	   MGMPayFramework.framework
				        
增加头文件引用
在需要调用 MGMPayFramework 的文件中,增加头文件引用。

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
配置返回 url 处理方法
本步骤指引开发者配置MGM客户端返回 url 处理方法
如示例 MGMSDKDemo\APAppDelegate.m 文件中,增加引用代码:

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
将 @implementation AppDelegate中以下代码中的 NSLog 改为实际业务处理代码:

	    - (BOOL)application:(UIApplication *)application
	        openURL:(NSURL *)url
	      sourceApplication:(NSString *)sourceApplication
	             annotation:(id)annotation {
	  
	        NSString *urlstr = [NSString stringWithFormat:@"%@",url];
	        if ([urlstr containsString:@"MGMPay"]) {
	            //跳转MGM进行支付,处理支付结果
	            [[MGMpaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
	                NSLog(@"result = %@",resultDic);
	            }];
	        }
	        return YES;
	    }

	    // NOTE: 9.0以后使用新API接口
	    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
	    {
	        NSString *urlstr = [NSString stringWithFormat:@"%@",url];
	        if ([urlstr containsString:@"MGMPay"]) {
	            //跳转MGM进行支付,处理支付结果
	            [[MGMpaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
	                NSLog(@"result = %@",resultDic);
	            }];
	        }
	        return YES;
	    }
				        
针对Demo的运行注意
1.如果商户要在某个文件中使用MGM的开发包类库,需增加引用头文件。

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
2.点击项目名称,点击 Build Settings 选项卡,在搜索框中,以关键字“search”搜索,对“Header Search Paths”增加头文件路径:$(SRCROOT)/项目名称。如果头文件信息已增加,可不必再增加。
3.点击项目名称,点击 Build Phases 选项卡,在“Link Binary with Librarles”选项中,新增“MGMPayFramework.framework”文件。如果商户项目中已有这个库文件,可不必再增加。
4、点击项目名称,点击 Info 选项卡,在“URL Types”选项中,点击“+”,在“URL Schemes”中输入“MGMPayDemo”。

	   NSString *appScheme = @"MGMPayDemo";
				        
注意:
这里的 URL Schemes 中输入的 MGMPayDemo,为测试 demo,实际商户的 app 中要填写独立的 scheme,建议跟商户的 app 有一定的标示度,要做到和其他的商户 app 不重复,否则可能会导致MGM返回的结果无法正确跳回商户 app。
代码示例运行逻辑
1.调用 (MGMPayFramework *)defaultService 类下面的支付接口函数,唤起MGM支付页面。

	   (void)payOrder:(NSString *)orderStr
	   fromScheme:(NSString *)schemeStr
	   callback:(CompletionBlock)completionBlock
				        
schemeStr 为 app 在 info.plist 注册的 scheme。
2.当这笔交易被买家支付成功后MGM上显示该笔交易成功,并提示用户“返回”。此时在 AppDelegate.m 的

	   - (BOOL)application:(UIApplication )application openURL:(NSURL )url sourceApplication:(NSString )sourceApplication annotation:(id)annotation
				        
中调用获取返回数据的代码(iOS 9.0 及以上需要在

	   - (BOOL)application:(UIApplication )app openURL:(NSURL )url options:(NSDictionary<NSString, id> *)options
				        
中执行):

	   [[MGMpaySDK defaultService]
	   processOrderWithPaymentResult:url
	   standbyCallback:^(NSDictionary *resultDic) {
	   NSLog(@"result = %@",resultDic);//返回的支付结果
	   }];
				        
注:resultStatus结果码含义
10000 订单支付成功
20000 用户未安装MGM客户端
其他 其它支付错误,具体可见后台参数说明
针对 Swift 接入 MGMPayFramework 的问题
如果项目使用 Swift 为开发语言,需要添加桥接文件,如 Bridging-Header.h。
同时,在项目 Build Settings 中设置桥接文件的位置(如下图所示)。
添加成功后,在桥接文件中写入。

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
如此,在需要调用 MGMPayFramework 的地方,即可直接使用,具体调用方式参照 OC。
注意:
运行时如果发生以下报错,
则在桥接文件中,写入

	   #import <UIKit/UIKit.h>
				        
iOS调用说明
接口名称:MGMPayFramework
接口描述:提供支付功能。
MGMpay 接口主要为商户提供订单支付功能。接口所提供的方法,如下表所示:
+(MGMpay *)defaultService; 获取服务实例。
-(void)payOrder:(NSString *)orderStr fromScheme:(NSString *)schemeStr callback:(CompletionBlock)completionBlock; 调起MGM客户端并传入scheme。
-(void)processOrderWithPaymentResult:(NSURL*)resultUrl standbyCallback:(CompletionBlock)completionBlock; 处理MGM客户端返回的url
1.快捷订单支付 iOS
方法名称:pay方法
方法原型:(void)payOrder:(NSString )orderStr fromScheme:(NSString )schemeStr callback:
(CompletionBlock)completionBlock;
方法功能:提供给商户快捷订单支付功能。
NSString* scheme 商户程序注册的URL protocol,供支付完成后回调商户程序使用。
(CompletionBlock)completionBlock 快捷支付开发包回调函数,返回是否能成功调起MGM App的结果。
NSString* orderString app支付请求参数字符串,主要包含商户的订单信息,key=value形式,以&连接。
orderStr 示例如下:

	   orderString=eyJhcHBJZCI6IjI4NzAzNTk5IiwicHJlcGF5SWQiOiJtbzIwMjAwMzA1MTQxODI1MTU0MTk0MTUiLCJhcHBLZXkiOiJkNDVkMmY1NzgyNjMxNDllZmU4ZTg2MWQwODBhYmYyNSIsInRpbWVzdGFtcCI6MTU4MzM4OTEwNSwibmFtZSI6Ilx1OWE2Y1x1NWM5Ylx1NTcyOFx1N2ViZiIsImV4dGVuc2lvbiI6Ilx1NmQ0Ylx1OGJkNTQiLCJwcmljZSI6IjIyNiIsInNpZ24iOiI3NDVBODc1QzI5NDgyRkUzNTIwNEJBRkZBNUI3N0Y3OSJ9
				        
2.处理客户端返回 url
方法名称:处理客户端方法
方法原型:-(void)processOrderWithPaymentResult:(NSURL*)resultUrl standbyCallback:
(CompletionBlock)completionBlock;
方法功能:设备已安装MGM客户端情况下,处理MGM客户端返回的url。
注意:
该方法必须实现,否则将会导致在安装手机MGM的情况下,支付结果无法正常同步返回。
NSURL *resultUrl MGM客户端回传的url
CompletionBlock completionBlock 本地安装了MGM客户端,且成功调用MGM客户端进行支付的情况下,会通过该completionBlock返回支付结果
备注:请在APPDelegate的

	   - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
				        
中调用该方法,iOS9.0及以上请在

	   - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
				        
中调用该方法,具体可参见Demo

Processuss d'intégration iOS MGM Money

Importation d'un code source
Activer Xcode,copier le fichier compressé du package IOS dans le fichier de projet,et importez-le dans le projet

	   MGMPayFramework.framework
				        
Ajouter des références au fichier d'en-tête
Ajouter la référence du fichier d'en-tête dans le fichier sur lequel on doit appeler de MGMPayFramework

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
Configuration de la méthode de traitement des URL de retour
Cette étape guide le développeur à configurer la méthode de traitement des URL de retour du coté client MGM
Ajouter le code de référence dans le fichier d'exemple MGMSDKDemo \ APAppDelegate.m, :

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
Remplacez le code NSLog dans @implementation AppDelegate par le code de traitement de service réel:

	    - (BOOL)application:(UIApplication *)application
	        openURL:(NSURL *)url
	      sourceApplication:(NSString *)sourceApplication
	             annotation:(id)annotation {
	  
	        NSString *urlstr = [NSString stringWithFormat:@"%@",url];
	        if ([urlstr containsString:@"MGMPay"]) {
	            //Accéder à MGM pour le paiement et traiter le résultat
	            [[MGMpaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
	                NSLog(@"result = %@",resultDic);
	            }];
	        }
	        return YES;
	    }

	    // NOTE: Utiliser une nouvelle interface API 9.0 après
	    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
	    {
	        NSString *urlstr = [NSString stringWithFormat:@"%@",url];
	        if ([urlstr containsString:@"MGMPay"]) {
	            //Accéder à MGM pour le paiement et traiter le résultat
	            [[MGMpaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
	                NSLog(@"result = %@",resultDic);
	            }];
	        }
	        return YES;
	    }
				        
Visionner le fonctionnement du demo
1. Si le commerçant souhaite utiliser la bibliothèque du kit de développement MGM dans un certain fichier,la référence d'en-tête doit être ajouté.

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
2. Cliquez sur le nom du projet, cliquez sur l'onglet Build setting, recherchez dans la zone de recherche avec le mot-clé "recherche" et ajoutez le chemin du fichier d'en-tête à "Chemins de recherche d'en-tête": $ (SRCROOT) / nom du projet. Si les informations du fichier d'en-tête ont été augmentées, il n'est plus nécessaire de les augmenter.
3. Cliquer sur le nom du projet, cliquez sur l'onglet Build Phases et ajoutez le fichier "MGMPayFramework.framework" dans l'option "Link Binary with Librarles". Si ce fichier existe déjà dans le projet marchand, il n'est plus nécéssaire d' ajouté.
4. Cliquez sur le nom du projet, puis cliquez sur l'onglet Info, dans l'option "Types d'URL", cliquez sur "+" et entrez "MGMPayDemo" dans le "Schémas d'URL".

	   NSString *appScheme = @"MGMPayDemo";
				        
Attention:
Le MGMPayDemo saisi dans les schémas d'URL ici c'est pour tester la démo. L'application du marchand réel doit être donc remplie avec un schéma indépendant. Il est recommandé d'avoir un certain degré de marquage avec d'autre application marchande. Les résultats renvoyés par MGM ne peuvent pas être correctement renvoyés à l'application marchande.
Exemple typique pour la logique de fonctionnement
1. Appelez la fonction d'interface de paiement sous la classe (MGMPayFramework *) defaultService pour appeler la page de paiement MGM.

	   (void)payOrder:(NSString *)orderStr
	   fromScheme:(NSString *)schemeStr
	   callback:(CompletionBlock)completionBlock
				        
SchemeStr est le schéma enregistré par l'application dans info.plist.
2. Lorsque l'acheteur a efféctué avec succès la transaction, MGM affiche le résultat de la transaction réussi et invite l'utilisateur à "revenir" dans AppDelegate.m

	   - (BOOL)application:(UIApplication )application openURL:(NSURL )url sourceApplication:(NSString )sourceApplication annotation:(id)annotation
				        
Appelez le code source afin d'obtenir les données de retours ( iOS 9.0 et supérieur doit être en exécution

	   - (BOOL)application:(UIApplication )app openURL:(NSURL )url options:(NSDictionary<NSString, id> *)options
				        
):

	   [[MGMpaySDK defaultService]
	   processOrderWithPaymentResult:url
	   standbyCallback:^(NSDictionary *resultDic) {
	   NSLog(@"result = %@",resultDic);//Résultat du paiement
	   }];
				        
Notes:resultStatus Contient le code de résultat
10000 Paiement efféctué avec succés
20000 L'utilisateur n'a pas encore installé MGM coté client
Autres Erreur de paiement,Voir la description des paramètres d'arrière-plan pour plus de détails
Visionner les problèmes de l'accés Swift sur MGMPayFramework
Si le projet utilise Swift comme langage de développement, vous devez ajouter un fichier de pont, comme Bridging-Header.h.
En même temps, définissez l'emplacement du fichier de pont dans les paramètres de création du projet (comme indiqué ci-dessous).
Une fois ajoutée ,entrer

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
dans le fichier de pont.
De cette façon, lorsque vous devez appeler MGMPayFramework, vous pouvez l'utiliser directement, reportez-vous à OC pour la méthode d'appel spécifique.
Attention:
Si l'erreur suivante se produit pendant le fonctionnement,
Entrer

	   #import <UIKit/UIKit.h>
				        
dans le fichier de pont
Instructions sur l'appel IOS
Nom de l'interface:MGMPayFramework
Description de l,interface:Fournir une fonctionnalité de paiement
L'interface MGMpay fournit principalement aux commerçants des fonctions de paiement. Les méthodes fournies par l'interface sont présentées dans le tableau suivant:
+(MGMpay *)defaultService; Obtenez une instance de service.
-(void)payOrder:(NSString *)orderStr fromScheme:(NSString *)schemeStr callback:(CompletionBlock)completionBlock; Ouvrez le client MGM et passez le schéma.
-(void)processOrderWithPaymentResult:(NSURL*)resultUrl standbyCallback:(CompletionBlock)completionBlock; Gérer l'URL retournée par le client MGM
1.Paiement rapide sur IOS
Nom de la méthode:Méthode pay
Prototype:(void)payOrder:(NSString )orderStr fromScheme:(NSString )schemeStr callback:
(CompletionBlock)completionBlock;
Fonction: Fournir aux commerçants une fonctionnalité de paiement rapide
NSString* scheme Le protocole URL enregistré par le programme est utilisé pour rappeler le programme marchand une fois que le paiement est faite.
(CompletionBlock)completionBlock La fonction de rappel du kit de développement de paiement rapide indique si l'application MGM peut être invoquée avec succès.
NSString* orderString Chaîne de paramètres de demande de paiement par application, contenant principalement les informations sur la commandecommerçant, clé = formulaire de valeur, connectée avec &
L'exemple orderStr est comme suit:

	   orderString=eyJhcHBJZCI6IjI4NzAzNTk5IiwicHJlcGF5SWQiOiJtbzIwMjAwMzA1MTQxODI1MTU0MTk0MTUiLCJhcHBLZXkiOiJkNDVkMmY1NzgyNjMxNDllZmU4ZTg2MWQwODBhYmYyNSIsInRpbWVzdGFtcCI6MTU4MzM4OTEwNSwibmFtZSI6Ilx1OWE2Y1x1NWM5Ylx1NTcyOFx1N2ViZiIsImV4dGVuc2lvbiI6Ilx1NmQ0Ylx1OGJkNTQiLCJwcmljZSI6IjIyNiIsInNpZ24iOiI3NDVBODc1QzI5NDgyRkUzNTIwNEJBRkZBNUI3N0Y3OSJ9
				        
2.Gérer le retour d'URL coté client
Nom du méthode:Gestion des méthodes coté client
Prototype:-(void)processOrderWithPaymentResult:(NSURL*)resultUrl standbyCallback:
(CompletionBlock)completionBlock;
Fonction:Lorsque l'application MGM client est installée sur le périphérique, l'URL renvoyée par le client MGM est traitée.
Attention:
Cette méthode doit être implémentée, sinon le résultat du paiement ne pourra pas être retourné de manière synchrone lorsque le téléphone mobile installe MGM.
NSURL *resultUrl URL retournée par le client MGM
CompletionBlock completionBlock Si l'application MGM client est installée localement et que l'application est appelée avec succès lors du paiement, le résultat du paiement sera retourné via le completionblock.
Remarque:Veuillez accéder dans APPDelegate

	   - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
				        
Appelez cette méthode, veuillez passer à iOS9.0 et supérieur

	   - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
				        
Appelez cette méthode, voir la démo pour plus de détails.

IOS MGM Money integration process

Importing source code
Activate Xcode , copy the compressed file from the IOS package to the project file , and import it into the project.

	   MGMPayFramework.framework
				        
Add references to the header file
Add the reference of the header file to the file on which we must call MGMPayFramework,

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
Configuring the method for handling return URL
This step guides the developer to configure the method of processing return URL on the MGM client side
Add the reference code to the example file MGMSDKDemo \ APAppDelegate.m:

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
Replace the NSLog code in @implementation AppDelegate with the actual service processing code:

	    - (BOOL)application:(UIApplication *)application
	        openURL:(NSURL *)url
	      sourceApplication:(NSString *)sourceApplication
	             annotation:(id)annotation {
	  
	        NSString *urlstr = [NSString stringWithFormat:@"%@",url];
	        if ([urlstr containsString:@"MGMPay"]) {
	            //Access MGM for payment and process the result
	            [[MGMpaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
	                NSLog(@"result = %@",resultDic);
	            }];
	        }
	        return YES;
	    }

	    // NOTE: 9.0 Then use new API interface 9.0
	    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
	    {
	        NSString *urlstr = [NSString stringWithFormat:@"%@",url];
	        if ([urlstr containsString:@"MGMPay"]) {
	            //Access MGM for payment and process the result
	            [[MGMpaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
	                NSLog(@"result = %@",resultDic);
	            }];
	        }
	        return YES;
	    }
				        
Watch how the demo works
1.If the merchant wishes to use the MGM development kit library in a certain file, the header reference must be added.

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
2.Click on the project name, click on the Build setting tab, search in the search box with the keyword "search" and add the path of the header file to "Header search paths ": $ (SRCROOT) / project name. If the information in the header file has been increased, it is no longer necessary to increase it.
3.Click on the project name, click on the Build Phases tab and add the file "MGMPayFramework.framework" in the "Link Binary with Librarles" option. If this file already exists in the merchant project, it is no longer necessary to be added.
4、Click on the project name, then click on the Info tab, in the "URL types" option, click on "+" and enter "MGMPayDemo" in the "URL schemes".

	   NSString *appScheme = @"MGMPayDemo";
				        
Warning:
The MGMPayDemo entered in the URL schemes here is for testing the demo. The application of the real merchant must therefore be filled with an independent scheme. It is recommended to have a certain degree of marking with other merchant application. The results returned by MGM cannot be correctly returned to the merchant application.
Typical example for operating logic
1.Call the payment interface function under the defaultService (MGMPayFramework *) class to call the MGM payment page.

	   (void)payOrder:(NSString *)orderStr
	   fromScheme:(NSString *)schemeStr
	   callback:(CompletionBlock)completionBlock
				        
SchemeStr is the schema saved by the application in info.plist.
2.When the buyer has successfully completed the transaction, MGM displays the result of the successful transaction and invites the user to "return" in AppDelegate.m

	   - (BOOL)application:(UIApplication )application openURL:(NSURL )url sourceApplication:(NSString )sourceApplication annotation:(id)annotation
				        
Call source code to get returns data (iOS 9.0 and above must be running in

	   - (BOOL)application:(UIApplication )app openURL:(NSURL )url options:(NSDictionary<NSString, id> *)options
				        
):

	   [[MGMpaySDK defaultService]
	   processOrderWithPaymentResult:url
	   standbyCallback:^(NSDictionary *resultDic) {
	   NSLog(@"result = %@",resultDic);//Payment result
	   }];
				        
Notes : resultStatus Contains the result code
10000 Payment made successfully
20000 The user has not yet installed MGM client side
Others Payment error, See description of background settings for more details
View Swift access problems on MGMPayFramework
If the project uses Swift as the development language, you must add a bridge file, such as Bridging-Header.h.
At the same time, define the location of the bridge file in the project creation parameters (as shown below).
Once added, enter

	   #import <MGMPayFramework/MGMPayFramework.h>
				        
in the bridge file.
That way, when you need to call MGMPayFramework, you can use it directly, refer to OC for the specific calling method.
Warning:
If the following error occurs during operation,
Enter

	   #import <UIKit/UIKit.h>
				        
In the bridge file
iOS call intructions
Interface name:MGMPayFramework
Interface description:Provide payment functionality.
The MGMpay interface mainly provides merchants with payment functions. The methods provided by the interface are presented in the following table :
+(MGMpay *)defaultService; Get service instance.
-(void)payOrder:(NSString *)orderStr fromScheme:(NSString *)schemeStr callback:(CompletionBlock)completionBlock; Bring up the MGM client and pass in the scheme.
-(void)processOrderWithPaymentResult:(NSURL*)resultUrl standbyCallback:(CompletionBlock)completionBlock; Handle the URL returned by the MGM client.
1.Fast payment in IOS
Method name:payMethod
Prototype:(void)payOrder:(NSString )orderStr fromScheme:(NSString )schemeStr callback:
(CompletionBlock)completionBlock;
Function:Provide to the merchants a fast payment functionality
NSString* scheme The URL protocol registered by the program is used to recall the merchant program after payment has been made.
(CompletionBlock)completionBlock The reminder function of the Quick Payment Development Kit indicates whether the MGM application can be successfully invoked.
NSString* orderString Payment request parameter chain by application, mainly containing information on the merchant order, key = value form, connected with &
The orderStr example is as follows:

	   orderString=eyJhcHBJZCI6IjI4NzAzNTk5IiwicHJlcGF5SWQiOiJtbzIwMjAwMzA1MTQxODI1MTU0MTk0MTUiLCJhcHBLZXkiOiJkNDVkMmY1NzgyNjMxNDllZmU4ZTg2MWQwODBhYmYyNSIsInRpbWVzdGFtcCI6MTU4MzM4OTEwNSwibmFtZSI6Ilx1OWE2Y1x1NWM5Ylx1NTcyOFx1N2ViZiIsImV4dGVuc2lvbiI6Ilx1NmQ0Ylx1OGJkNTQiLCJwcmljZSI6IjIyNiIsInNpZ24iOiI3NDVBODc1QzI5NDgyRkUzNTIwNEJBRkZBNUI3N0Y3OSJ9
				        
2.Manage return URL on client side
Method name:Client-side method management
Protoype:-(void)processOrderWithPaymentResult:(NSURL*)resultUrl standbyCallback:
(CompletionBlock)completionBlock;
Function:When the MGM client application is installed on the device, the URL returned by the MGM client is processed.
Warning:
This method must be implemented, otherwise the result of the payment cannot be returned synchronously when the mobile phone installs MGM.
NSURL *resultUrl URL returned by the MGM client
CompletionBlock completionBlock If the MGM client application is installed locally and the application is called successfully during payment, the payment result will be returned via the completionblock
Note : Please access in APPDelegate

	   - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
				        
Call this method, please upgrade to iOS9.0 and above 

	   - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
				        
Call this method, see the Demo for more details.