// 加密 转换为字符串
func sign(dict:Dictionary<String,String>?,_ sign:String) -> String {
let sortDict = dict?.sort{ $0.0 < $1.0 }
var params = ""
for (key,value) in sortDict! {
params += "(key)=(value)&"
}
let index = params.endIndex.advancedBy(-1)
params = params.substringToIndex(index)
let signStr = sign + params + sign
return params + "&sign=" + md5(signStr)
}
// md5加密
func md5(sstring : String) -> String{
let str = sstring.cStringUsingEncoding(NSUTF8StringEncoding)
let strLen = CC_LONG(sstring.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
let digestLen = Int(CC_MD5_DIGEST_LENGTH)
let buffer = UnsafeMutablePointer<UInt8>.alloc(digestLen)
CC_MD5(str!,strLen,buffer)
let hash = NSMutableString()
for i in 0 ..< digestLen {
hash.appendFormat("%02x", buffer[i])
}
buffer.dealloc(digestLen)
return String(format: hash as String)
}
// 获取Package Name 和 BundleID
NSBundle.mainBundle().bundleIdentifier,"bundleID"
// app 显示名称
NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName")