国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iOS開發日記3-微信支付

2019-11-14 18:31:07
字體:
來源:轉載
供稿:網友

今天博主有一個微信支付的需求,遇到了一些困難點,在此和大家分享,希望能夠共同進步.

1.申請AppID,導入依賴庫,配置URL Scheme這里就不深究了,各位看官請自行百度.

2.在AppDelegate中導入頭文件,遵守WXApiDelegate,然后在launch里注冊AppID.

3.在支付界面導入頭文件,創建支付對象,調起微信

//調起微信支付,傳入參數

PayReq* req = [[[PayReq alloc] init]autorelease];

req.openID = APPI_ID;

req.partnerId = PARTNER_ID;

req.PRepayId = prePayid;

req.nonceStr = nonce_str;

req.timeStamp = now;

req.package = package;

req.sign = sign;

[WXApi safeSendReq:req];

4.微信支付的回調需要添加在AppDelegate中

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

{

 

     //返回應用后的回調,通過handleOpenURL進入微信支付的回調onResp:(BaseResp*)resp

         return [WXApi handleOpenURL:url delegate:self];

}

-(void) onResp:(BaseResp*)resp

{

if ([resp isKindOfClass:[PayResp class]])

{

PayResp *response = (PayResp *)resp;

NSString *strTitle = [NSString stringWithFormat:@"支付結果"];

NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", response.errCode];

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitlemessage:strMsg  delegate:self cancelButtonTitle:@"OK"  otherButtonTitles:nil, nil];

[alert show];

switch (response.errCode) {

case WXSuccess: {

NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object:@"success"];

[[NSNotificationCenter defaultCenter] postNotification:notification];

break;

}

default: {

NSNotification *notification = [NSNotification notificationWithName:ORDER_PAY_NOTIFICATION object:@"fail"];

[[NSNotificationCenter defaultCenter] postNotification:notification];

break;

}

}

}

}

但是將微信支付相關的代碼全部寫到AppDelegate中又會顯得代碼冗余,這時我們需要創建通知,在成功回調后發出通知,在支付界面監聽回調,完成支付.

5.在監聽回調中,上傳我們從微信支付中獲得的參數,完成支付.

 

http://www.jianshu.com/p/97d38b00e53d?plg_nld=1&plg_auth=1&plg_nld=1&plg_dev=1&plg_uin=1&plg_usr=1&plg_vkey=1&plg_nld=1&plg_uin=1&plg_nld=1&plg_auth=1&plg_usr=1&plg_vkey=1&plg_dev=1

 

http://www.tuicool.com/articles/32UFBzQ?plg_nld=1&plg_uin=1&plg_auth=1&plg_nld=1&plg_usr=1&plg_vkey=1&plg_dev=1

 

http://www.jianshu.com/p/6e75a450dcc4?plg_nld=1&plg_uin=1&plg_auth=1&plg_nld=1&plg_usr=1&plg_vkey=1&plg_dev=1


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新竹市| 遵义县| 册亨县| 米脂县| 托里县| 蓬安县| 枞阳县| 桂平市| 民丰县| 炉霍县| 左贡县| 罗城| 荥经县| 渝中区| 洛隆县| 永城市| 栾川县| 宜兴市| 荣昌县| 榆树市| 贡觉县| 宜城市| 南投市| 新巴尔虎右旗| 清水河县| 科技| 海安县| 高阳县| 潜山县| 辽源市| 安泽县| 南溪县| 新兴县| 长葛市| 鲁山县| 鸡泽县| 枣庄市| 大邑县| 文登市| 道孚县| 大方县|