# midasPresent
### midasPresent
开通了虚拟支付的小游戏,可以通过该接口赠送游戏币给某个用户。
#### 正式环境
```
<pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln">POST https</span><span class="pun">:</span><span class="com">//api.weixin.qq.com/cgi-bin/midas/present?access_token=ACCESS_TOKEN</span></code></li></ol>
```
#### 沙箱环境
```
<pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln">POST https</span><span class="pun">:</span><span class="com">//api.weixin.qq.com/cgi-bin/midas/sandbox/present?access_token=ACCESS_TOKEN</span></code></li></ol>
```
#### 参数
##### string openid
用户唯一标识符
##### string appid
小程序 appId
##### string offer\_id
米大师分配的offer\_id
##### number ts
UNIX 时间戳,单位是秒
##### string zone\_id
游戏服务器大区id,游戏不分大区则默认zoneId ="1",String类型。如果应用选择支持角色,则角色ID接在分区ID号后用"\_"连接。
##### string pf
平台 安卓:android
##### string user\_ip
用户外网 IP
##### string bill\_no
订单号,业务需要保证全局唯一;相同的订单号不会重复扣款。长度不超过63,只能是数字、大小写字母\_-|\*@
##### number present\_counts
赠送游戏币的个数,不能为0
##### string sig
以上所有参数(含可选最多9个)+uri+米大师密钥,用 HMAC-SHA256签名,详见 [米大师支付签名算法](https://developers.weixin.qq.com/minigame/dev/tutorial/open-ability/midas-signature.html)
##### string access\_token
[接口调用凭证](/read/wechat-game-api/297.md)
##### string mp\_sig
以上所有参数(含可选最多11个)+uri+session\_key,用 HMAC-SHA256签名,详见 [米大师支付签名算法](https://developers.weixin.qq.com/minigame/dev/tutorial/open-ability/midas-signature.html)
#### 返回值
##### Object
返回的 JSON 数据包
属性类型说明支持版本errcodenumber错误码errmsgstring错误信息balancenumber赠送后的余额bill\_nostring赠送游戏币的订单号**errcode 的合法值**
值说明0请求成功-1系统繁忙,此时请开发者稍候再试90009mp\_sig签名错误90010用户未登录或登录态已过期90011sig签名错误90012订单已存在90017没有调用接口的权限90018参数错误#### POST 数据格式:JSON
```
<pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pun">{</span></code></li>
<li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"openid"</span><span class="pun">:</span><span class="str">"odkx20ENSNa2w5y3g_qOkOvBNM1g"</span><span class="pun">,</span></code></li>
<li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"appid"</span><span class="pun">:</span><span class="str">"wx1234567"</span><span class="pun">,</span></code></li>
<li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"offer_id"</span><span class="pun">:</span><span class="str">"12345678"</span><span class="pun">,</span></code></li>
<li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"ts"</span><span class="pun">:</span><span class="lit">1507530737</span><span class="pun">,</span></code></li>
<li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"zone_id"</span><span class="pun">:</span><span class="str">"1"</span><span class="pun">,</span></code></li>
<li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"pf"</span><span class="pun">:</span><span class="str">"android"</span><span class="pun">,</span></code></li>
<li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"present_counts"</span><span class="pun">:</span><span class="lit">233</span><span class="pun">,</span></code></li>
<li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"bill_no"</span><span class="pun">:</span><span class="str">"BillNo_123"</span><span class="pun">,</span></code></li>
<li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"sig"</span><span class="pun">:</span><span class="str">"e53e5241bbb014b3a9fcc221d66fecab8734b53fe94d7a8c65180e175e29f443"</span><span class="pun">,</span></code></li>
<li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln"> </span><span class="str">"mp_sig"</span><span class="pun">:</span><span class="str">"39271a12d8d56b0395981a0990a9e75ae239c54f419cb6235399fe70acf8ccfb"</span></code></li>
<li class="l1"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pun">}</span></code></li>
</ol>
```
> 原文: <https://developers.weixin.qq.com/minigame/dev/api/midas-payment/midasPresent.html>
- 致谢
- 渲染
- 画布
- wx.createCanvas
- Canvas
- .toTempFilePath
- .toTempFilePathSync
- .getContext
- .toDataURL
- RenderingContext
- 图片
- wx.createImage
- Image
- 字体
- wx.getTextLineHeight
- wx.loadFont
- 帧率
- wx.setPreferredFramesPerSecond
- cancelAnimationFrame
- requestAnimationFrame
- 分包加载
- wx.loadSubpackage
- LoadSubpackageTask
- .onProgressUpdate
- 设备
- 设备方向
- wx.startDeviceMotionListening
- wx.stopDeviceMotionListening
- wx.onDeviceMotionChange
- 加速计
- wx.startAccelerometer
- wx.stopAccelerometer
- wx.onAccelerometerChange
- 剪贴板
- wx.getClipboardData
- wx.setClipboardData
- 罗盘
- wx.startCompass
- wx.stopCompass
- wx.onCompassChange
- 陀螺仪
- wx.startGyroscope
- wx.stopGyroscope
- wx.onGyroscopeChange
- 电量
- wx.getBatteryInfo
- wx.getBatteryInfoSync
- 网络
- wx.getNetworkType
- wx.onNetworkStatusChange
- 振动
- wx.vibrateShort
- wx.vibrateLong
- 性能
- wx.onMemoryWarning
- 屏幕
- wx.getScreenBrightness
- wx.setKeepScreenOn
- wx.setScreenBrightness
- 转屏
- wx.onDeviceOrientationChange
- wx.offDeviceOrientationChange
- 系统
- 系统信息
- wx.getSystemInfo
- wx.getSystemInfoSync
- 系统事件
- wx.onAudioInterruptionBegin
- wx.offAudioInterruptionBegin
- wx.onAudioInterruptionEnd
- wx.offAudioInterruptionEnd
- wx.onError
- wx.offError
- 生命周期
- wx.exitMiniProgram
- wx.getLaunchOptionsSync
- wx.onHide
- wx.offHide
- wx.onShow
- wx.offShow
- 触摸事件
- wx.onTouchStart
- wx.offTouchStart
- wx.onTouchMove
- wx.offTouchMove
- wx.onTouchEnd
- wx.offTouchEnd
- wx.onTouchCancel
- wx.offTouchCancel
- Touch
- 位置
- wx.getLocation
- 媒体
- 图片
- wx.chooseImage
- wx.previewImage
- wx.saveImageToPhotosAlbum
- 音频
- wx.createInnerAudioContext
- wx.getAvailableAudioSources
- wx.setInnerAudioOption
- InnerAudioContext
- .pause
- .stop
- .seek
- .destroy
- .offCanplay
- .onPlay
- .offPlay
- .onPause
- .offPause
- .onStop
- .offStop
- .onEnded
- .offEnded
- .onTimeUpdate
- .offTimeUpdate
- .onError
- .onCanplay
- .offError
- .onWaiting
- .offWaiting
- .onSeeking
- .offSeeking
- .onSeeked
- .offSeeked
- .play
- 录音
- wx.getRecorderManager
- RecorderManager
- .start
- .pause
- .resume
- .stop
- .onStart
- .onResume
- .onPause
- .onStop
- .onFrameRecorded
- .onError
- .onInterruptionBegin
- .onInterruptionEnd
- 视频
- wx.createVideo
- Video
- .onWaiting
- .offWaiting
- .onPlay
- .offPlay
- .onPause
- .offPause
- .onEnded
- .offEnded
- .onTimeUpdate
- .offTimeUpdate
- .onError
- .offError
- .destroy
- .play
- .pause
- .stop
- .seek
- .requestFullScreen
- .exitFullScreen
- 文件
- wx.getFileSystemManager
- FileSystemManager
- .access
- .accessSync
- .appendFile
- .appendFileSync
- .saveFile
- .saveFileSync
- .getSavedFileList
- .removeSavedFile
- .copyFile
- .copyFileSync
- .getFileInfo
- .mkdir
- .mkdirSync
- .readFile
- .readFileSync
- .readdir
- .readdirSync
- .rename
- .renameSync
- .rmdir
- .rmdirSync
- .stat
- .statSync
- .unlink
- .unlinkSync
- .unzip
- .writeFile
- .writeFileSync
- Stats
- .isDirectory
- .isFile
- 网络
- 下载
- wx.downloadFile
- DownloadTask
- .onProgressUpdate
- .abort
- 发起请求
- wx.request
- RequestTask
- .abort
- WebSocket
- wx.connectSocket
- wx.closeSocket
- wx.sendSocketMessage
- wx.onSocketOpen
- wx.onSocketClose
- wx.onSocketMessage
- wx.onSocketError
- SocketTask
- .close
- .onOpen
- .onClose
- .onError
- .onMessage
- .send
- 上传
- wx.uploadFile
- UploadTask
- .onProgressUpdate
- .abort
- 开放接口
- 游戏圈
- wx.createGameClubButton
- GameClubButton
- .onTap
- .offTap
- .show
- .hide
- .destroy
- 开放数据
- wx.getFriendCloudStorage
- wx.getGroupCloudStorage
- wx.getUserCloudStorage
- wx.removeUserCloudStorage
- wx.setUserCloudStorage
- wx.getSharedCanvas
- UserGameData
- KVData
- removeUserStorage
- setUserStorage
- 授权
- wx.authorize
- 防沉迷
- wx.checkIsUserAdvisedToRest
- 用户信息
- wx.getUserInfo
- wx.createUserInfoButton
- UserInfo
- UserInfoButton
- .show
- .hide
- .destroy
- .onTap
- .offTap
- 微信运动
- wx.getWeRunData
- 设置
- wx.getSetting
- wx.openSetting
- wx.createOpenSettingButton
- OpenSettingButton
- .onTap
- .offTap
- .show
- .hide
- .destroy
- AuthSetting
- 登录
- wx.login
- wx.checkSession
- checkSessionKey
- code2Session
- 意见反馈
- wx.createFeedbackButton
- FeedbackButton
- .onTap
- .offTap
- .show
- .hide
- .destroy
- 小程序跳转
- wx.navigateToMiniProgram
- 客服消息
- wx.openCustomerServiceConversation
- 开放数据域
- wx.getOpenDataContext
- wx.onMessage
- OpenDataContext
- .postMessage
- 接口调用凭证
- getAccessToken
- 内容安全
- imgSecCheck
- msgSecCheck
- 二维码
- createWXAQRCode
- getWXACode
- getWXACodeUnlimit
- 调试
- wx.setEnableDebug
- console
- .groupEnd
- .debug
- .log
- .info
- .warn
- .error
- .group
- 数据缓存
- wx.getStorage
- wx.getStorageSync
- wx.setStorage
- wx.setStorageSync
- wx.removeStorage
- wx.removeStorageSync
- wx.clearStorage
- wx.clearStorageSync
- wx.getStorageInfo
- wx.getStorageInfoSync
- 更新
- wx.getUpdateManager
- UpdateManager
- .onCheckForUpdate
- .onUpdateReady
- .onUpdateFailed
- .applyUpdate
- Worker
- wx.createWorker
- Worker
- .postMessage
- .onMessage
- .terminate
- 转发
- wx.getShareInfo
- wx.hideShareMenu
- wx.showShareMenu
- wx.updateShareMenu
- wx.shareAppMessage
- wx.onShareAppMessage
- wx.offShareAppMessage
- 广告
- wx.createRewardedVideoAd
- wx.createBannerAd
- RewardedVideoAd
- .load
- .show
- .onLoad
- .offLoad
- .onError
- .offError
- .onClose
- .offClose
- BannerAd
- .show
- .hide
- .destroy
- .onResize
- .offResize
- .onLoad
- .offLoad
- .onError
- .offError
- 界面
- 交互
- wx.showToast
- wx.showModal
- wx.hideToast
- wx.showLoading
- wx.hideLoading
- wx.showActionSheet
- 菜单
- wx.getMenuButtonBoundingClientRect
- wx.setMenuStyle
- 键盘
- wx.showKeyboard
- wx.hideKeyboard
- wx.updateKeyboard
- wx.onKeyboardInput
- wx.offKeyboardInput
- wx.onKeyboardConfirm
- wx.offKeyboardConfirm
- wx.onKeyboardComplete
- wx.offKeyboardComplete
- 状态栏
- wx.setStatusBarStyle
- 窗口
- wx.onWindowResize
- wx.offWindowResize
- 性能
- wx.getPerformance
- wx.triggerGC
- Performance
- .now
- 虚拟支付
- wx.requestMidasPayment
- midasCancelPay
- midasGetBalance
- midasPay
- midasPresent
- 定时器
- setTimeout
- clearTimeout
- setInterval
- clearInterval