• swift 集成支付宝遇到的问题


    移动端做加密,安卓和ios的私钥一定要匹配。比如安卓先生成了私钥和公钥,并且把公钥上传到支付宝管理平台了。这时候ios端无法通过公钥生成私钥,只能拿安卓的私钥转换成ios私钥,才能和支付宝上的应用公钥匹配

    ios段接支付宝可以,将uiappdelegate中的这个方法先写好,等支付宝支付失败后跳转到app时,就会打印错误日志,方便调试

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    
            if (url.host == "safepay") {
    
                // 支付跳转支付宝钱包进行支付,处理支付结果
    
                AlipaySDK.defaultService().processOrder(withPaymentResult: url, standbyCallback: { (resultDic:[AnyHashable : Any]?) in
    
                    
    
                    if let Alipayjson = resultDic as NSDictionary?{
    
                        let resultStatus = Alipayjson.value(forKey: "resultStatus") as! String
    
                        if resultStatus == "9000"{
    
                            print("OK")
    
                            
    
                            let resposeStr =  Alipayjson["result"] as! String
    
                            let arr1 = resposeStr.components(separatedBy: ""out_trade_no":"")
    
                            let arr2 = arr1.last
    
                            let tadingno = arr2?.components(separatedBy: ""}").first
    
                            
    
                            
    
                            NotificationCenter.default.post(name: NSNotification.Name.init("paySuccess"), object: nil, userInfo: ["out_trade_no":tadingno ?? ""])
    
                            
    
                        }else if resultStatus == "8000" {
    
                            
    
                            print("正在处理中")
    
                            
    
                        }else if resultStatus == "4000" {
    
                            NotificationCenter.default.post(name:  NSNotification.Name.init("payFeild"), object: nil, userInfo: ["warning":"订单支付失败"])
    
                            print("订单支付失败");
    
                            WWLog(message: resultDic)
    
                            
    
                        }else if resultStatus == "6001" {
    
                            NotificationCenter.default.post(name:  NSNotification.Name.init("payFeild"), object: nil, userInfo: ["warning":"已取消支付"])
    
                            
    
                            print("用户中途取消")
    
                            
    
                        }else if resultStatus == "6002" {
    
                            print("网络连接出错")
    
                            NotificationCenter.default.post(name:  NSNotification.Name.init("payFeild"), object: nil, userInfo: ["warning":"网络连接出错"])
    
                            
    
                        }
    
                    }
    
                    
    
                    
    
                    
    
                    
    
                })
    
                // 授权跳转支付宝钱包进行支付,处理支付结果
    
                AlipaySDK.defaultService().processAuth_V2Result(url, standbyCallback: { (resultDic:[AnyHashable : Any]?) in
    
                    
    
                    // 解析 auth code
    
                    let result = resultDic?["result"] as! String;
    
                    var authCode : String? = nil;
    
                    if (result.lengthOfBytes(using: String.Encoding.utf8) > 0) {
    
                        let resultArr = result.components(separatedBy: "&")
    
                        
    
                        for subResult in resultArr {
    
                            if (subResult.lengthOfBytes(using: String.Encoding.utf8) > 10 && subResult.hasPrefix("auth_code=")) {
    
                                let index = "auth_code=".endIndex
    
                                authCode = subResult.substring(from:index )
    
                                break;
    
                            }
    
                        }
    
                    }
    
                    
    
                })
    
            }
    
            
    
            return true
    
        }
  • 相关阅读:
    Unity WebGL打包发布报错
    Makefile:4: *** missing separator. Stop.
    Unity使用VSCode没有代码提示/代码无法折叠
    Unreal Engine is exiting due to D3D device being lost
    使用Doxygen生成UE4的chm格式API文档
    'UTextRenderComponent::SetText': Passing text as FString is deprecated, please use FText instead (likely via a LOCTEXT)
    f4v格式视频播放失败
    Unity自定义Button组件Transition
    mysql安装步骤
    ansible 安装
  • 原文地址:https://www.cnblogs.com/heyode/p/6893075.html
Copyright © 2020-2023  润新知