支付宝:
let order = Order()
order.partner = partner;
order.seller = seller;
order.tradeNO = product.orderId; //订单ID(由商家自行制定)
order.productName = product.subject as String; //商品标题
order.productDescription = product.body; //商品描述
order.amount = NSString(format: "%.2f", floatPrice) as String//商品价格
order.notifyURL = "*******.aspx"; //回调URL
order.service = "mobile.securitypay.pay";
order.paymentType = "1";
order.inputCharset = "utf-8";
order.itBPay = "30m";
order.showUrl = "m.alipay.com";
//应用注册scheme,在AlixPayDemo-Info.plist定义URL types
let appScheme = "alisdkyft";
//将商品信息拼接成字符串
let orderSpec = order.description
print("orderSpec = \(orderSpec)")
//获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
let signer = CreateRSADataSigner(privateKey)
let signedString = signer.signString(orderSpec)
//将签名成功字符串格式化为订单字符串,请严格按照该格式
let orderString:String?
if(signedString != nil){
orderString = "\(orderSpec)&sign=\"\(signedString)\"&sign_type=\"RSA\""
AlipaySDK.defaultService().payOrder(orderString, fromScheme: appScheme)
注意需要按照支付宝官方文档 配置
二微信:
class func weixinzhifu(prepayid:String,price:String){
let dic = ["pis_yzm":securitycode,"pis_ordernumber":prepayid,"pis_chargeamt":price]
DBService.WeiXinPay(dic, block: { (result) -> Void in
let data = result.dataUsingEncoding(NSUTF8StringEncoding)
let json = JSON(data:data!)
print("zlzjson\(json)")
if(json["code"].stringValue == "0"){
let re = PayReq()
re.openID = WEIXIN_APPID
re.partnerId = WEIXIN_PARTNERID
re.prepayId = json["prepayId"].stringValue
re.package = "Sign=WXPay"
re.nonceStr = json["nonceStr"].stringValue
re.timeStamp = (UInt32)(json["timeStamp"].stringValue)!
re.sign = json["Sign"].stringValue
// 客户端自动生成二次签名
// var str = "appid=*************&noncestr=\(re.nonceStr)&package=\(re.package)&partnerid=\(re.partnerId)&prepayid=\(re.prepayId)×tamp=\(re.timeStamp)"
// print(str)
// var zlzstr = str + "&key=*******"
// print(zlzstr)
// re.sign = (zlzstr.md5).uppercaseString
WXApi.sendReq(re)
// request.sign=[md5 createMD5SingForPay:@"*******" partnerid:request.partnerId prepayid:request.prepayId package:request.package noncestr:request.nonceStr timestamp:request.timeStamp];
}
})
}
注意:sign 不是后台第一次生成的sign 需要二次生成 用到 字段是客户端发起请求的 参数;
三 :银联:
class func yinlian(prepayid:String,price:String){
print("prepayid:\(prepayid)")
let dic = ["pis_yzm":securitycode,"pis_ordernumber":prepayid,"pis_chargeamt":price]
DBService.UnionPay(dic, block: { (result) -> Void in
let data = result.dataUsingEncoding(NSUTF8StringEncoding)
let json = JSON(data:data!)
print("yinlian tn: \(json)")
if(json["code"].stringValue == "0"){
let tn = json["tn"].stringValue
let yinlianControl = UPPaymentControl.defaultControl();
var zlz = yinlianControl.startPay(tn, fromScheme: "UnionPay", mode: "01", viewController: nil)
if(zlz){
print("yes")}
else{
print("no")
}
}
})
}
注意:需要后台去银联后台获取到tn值;
四 招商wap版:
//
// epayViewController.swift
// yft
//
// Created by mac on 16/7/14.
// Copyright © 2016年 Tongjialin. All rights reserved.
//
import UIKit
class epayViewController: UIViewController {
var webViewPay = UIWebView()
var BranchID = "0574" //(必填) 商户开户分行号
var CoNo = "000641" //(必填) 商户号
var BillNo = "123456" //(必填) 订单号
var Amount = "1"//(必填) 软妹币
var Date = ""//(必填) 支付日期
var ExpireTimeSpan = ""//(选填)订单过期时间跨度,必须为大于零的整数
var MerchantUrl="" //支付结果通知命令中参数之前的部分,不允许带端口号,长度不能超过128个字节。例如: http://www.merchant.com/path/notify.dll。
var MerchantPara = ""//商户需要银行在支付结果通知中转发的商户参数。
var MerchantRetUrl = ""//如果提供了这个字段,手机支付界面上将出现“返回按钮”。客户点击“返回按钮”,将跳转到MerchantRetUrl与MerchantRetPara所指定的地址
var MerchantRetPara = ""//详见MerchantRetUrl中的说明。
var MerchantCode = "|VVzjS4SoORA7qHMznYbqP0jncJ5ihZGRaOOIrvNJWBKhaSMz0Ah3VGg1WyKJktSV/1ILYiUy7h3i2kwbr9F5IJnr1SeCPf*EKCX4aXjrE53wymq9uTVbzFPB76gFmekpx8N3q062JpSLlbsIKtPv4VWrzKKId4avr6//rG0PIrjlWrR371Wa*g==|74c8fba569fbe3ce1b8911a793cd5a8bfbd15cbd"// (总行要求必填)商户对订单信息的签名,用于防篡改,建议商户传送并申请强制校验商户校验码。详见“商户校验码.doc”说明。
var detailURL = "";
override func viewDidLoad() {
super.viewDidLoad()
var date = NSDate()
var timeFormatter = NSDateFormatter()
timeFormatter.dateFormat = "yyyMMdd"
var strNowTime = timeFormatter.stringFromDate(date) as String
self.Date = strNowTime
self.Date = "20160727"
print(self.Date)
detailURL = "http://61.144.248.29:801/netpayment/BaseHttp.dll?PrePayWAP&BranchID=\(BranchID)&CoNo=\(CoNo)&BillNo=\(BillNo)&Amount=\(Amount)&Date=\(Date)&ExpireTimeSpan=\(ExpireTimeSpan)&MerchantUrl=\(MerchantUrl)&MerchantPara=\(MerchantPara)&MerchantRetUrl=\(MerchantRetUrl)&MerchantRetPara=\(MerchantRetPara)&MerchantCode=\(MerchantCode)"
var str = detailURL.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
self.webViewPay = UIWebView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight))
print("ssss\(detailURL)")
var url = NSURL(string: str)
var urlRequest = NSURLRequest(URL: url!)
self.view.addSubview(webViewPay)
webViewPay.loadRequest(urlRequest)
}
}
注意 : 需要后台去给字段加密,在测试环境下 商户秘钥是空,