--Google示例--result,回调事件的类型--transaction,用于成功购买后结束此次交易的参数--transactionid,谷歌返回的订单号--productid,购买产品的ID--count,购买产品的数量--token,谷歌返回的json数据,用于服务器向谷歌校验订单--errorcode,失败的类型 -- _InAppPurchase.UNKNOWN,未知错误 -- _InAppPurchase.ClientInvalid,手机支付插件不可用 -- _InAppPurchase.Cancelled,用户取消 -- _InAppPurchase.PaymentInvalid,productid不存在 -- _InAppPurchase.NotAllowed,无法购买或结束购买,同一个产品在结束购买前不允许再次购买;没有购买的商品不允许结束购买 -- _InAppPurchase.NotAvailable,谷歌支付请忽略 -- _InAppPurchase.ArgumentsInvalid,参数不可用 -- _InAppPurchase.RemoteException,网络错误 -- _InAppPurchase.VerificationFailed,签名验证失败--ignore,如果不是upay支付,请忽略此参数--signature,发送给服务器,判断此次购买是否被篡改callback = function(result,transaction,transactionid,productid,count,token,errorcode,ignore,signature) print('result:'..result,'transaction:'..transaction,'transactionid:'..transactionid,'productid:'..productid,'count:'..count,'token:'..token,'errorcode:'..errorcode,'ignore:'..ignore,'signature:'..signature) if result == _InAppPurchase.InitSuccess then --初始化成功 elseif result == _InAppPurchase.InitFailed then --初始化失败,可以根据errorcode给用户提示 elseif result == _InAppPurchase.PaySuccess then --购买成功 --发送token,signature给服务器,让服务器验证订单状态 --游戏逻辑 --结束此次购买 print('结束此次购买') _iap:finishSuc(transaction) end elseif result == _InAppPurchase.PayFailed then --购买失败 --根据errorcode提示给用户 elseif result == _InAppPurchase.FinishSuccess then --结束购买成功 --游戏逻辑 elseif result == _InAppPurchase.FinishFailed then --结束购买失败 --根据errorcode提示给用户 endend--productid,在谷歌后台获取productid = 'gas'count = 1userdata = 'thisisasamplecode'--publickey,在谷歌后台获取publickey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvQUJPbui/udU2lklZQbcUKq8C+autMngaGLl64kQOhbl3uN/C6re003BFIaqTbiivGzmOVYdRXnTaUoobdhJaqGin6scZtbHr9QfYuOwGloKsQTJvQr4z15AGsIkgvwR945aIknBZNQ36PVUYSZkgztPhO/N4VdF1F9kSmtC49UYDuxcUWPWGxZQ8Zy6mPAT7y0AsnR4EWqYWVSIn5G+nvPJ94ryjxvrPbbAopvwE+xgdsAGWSrY5uOXyX2nPyW7itsPwIfPJix1Z9psXLAPM+KZEaN8QtKkVQgwoMSelz9RqP9hsMx9S9YNjla34xKWqiHhKPa/XPEFSHvlks4ShQIDAQAB'_app:onTouchEnd(function(x,y) if x < _rd.w/2 then _iap:init(publickey,callback) else _iap:purchase(productid,count,userdata) endend)
--Apple示例--result,回调事件的类型--transaction,用于购买失败后结束此次交易的参数--transactionid,用于购买成功后结束此次交易的参数--productid,购买产品的ID--count,购买产品的数量--token,苹果返回的支付验证码,用于服务器向苹果校验订单--errorcode,失败的类型 -- _InAppPurchase.UNKNOWN,未知错误 -- _InAppPurchase.ClientInvalid,手机内购不可用 -- _InAppPurchase.Cancelled,用户取消 -- _InAppPurchase.PaymentInvalid,productid不存在 -- _InAppPurchase.NotAvailable,商品不可用 -- _InAppPurchase.ArgumentsInvalid,苹果支付请忽略 -- _InAppPurchase.RemoteException,网络错误 -- _InAppPurchase.VerificationFailed,苹果支付请忽略--ignore,如果不是upay支付,请忽略此参数--userdata,苹果支付请忽略callback = function(result,transaction,transactionid,productid,count,token,errorcode,ignore,userdata) print('result:'..result,'transaction:'..transaction,'transactionid:'..transactionid,'productid:'..productid,'count:'..count,'token:'..token,'errorcode:'..errorcode,'ignore:'..ignore,'userdata:'..userdata) if result == _InAppPurchase.PaySuccess then --购买成功 --发送token给苹果服务器,验证订单状态,需游戏自行向苹果服务器发送验证,详情见服务器说明文档.docx --游戏逻辑 --结束此次购买 _iap:finishSuc(transactionid) elseif result == _InAppPurchase.PayFailed then --购买失败 --根据errorcode提示给用户 --结束此次购买 _iap:finishFail(transaction) endend--productid,在苹果后台获取productid = 'gas'count = 1_app:onTouchEnd(function(x,y) if x < _rd.w/2 then _iap:init(callback) else --设备是否开启内购功能 if _iap.canPayment then _iap:purchase(productid,count) end endend)