公众号云调用

在公众号网页中调用到已授权的小程序云开发云函数中时,在云函数中可以发起公众号云调用,即调用公众号的服务端接口。公众号服务端接口在云函数 SDK 中的使用方式是统一的,可以从其 HTTP 形式中直接推断出 SDK 接口的调用方式:对云调用方式,调用时参数与 HTTP 需求的参数一致,但是无需传入 access_token,同时所有的参数无论 get/post 都只需作为接口参数 JS 对象中的一个字段传入即可。

而对于 FormData 的请求,如果一个参数的类型是 Buffer,则其字段应传入有如下字段的对象:

属性 类型 默认值 必填 说明
contentType string 数据类型,传入 MIME Type
value Buffer 文件 Buffer

示例 1:JSON POST

以用户标签管理中的创建标签的服务端接口为例,其调用示例如下:

cloud.openapi({ appid: '公众号 AppID' }).officialAccount.tags.create({
  tag: {
    name: '标签名',
  },
})

示例 2:FORM POST

假设文档要求是 POST FormData,以新增临时素材为例,其调用示例如下:

cloud.openapi({ appid: '公众号 AppID' }).officialAccount.media.upload({
  type: '某个类型',
  media: {
    contentType: 'image/png',
    value: Buffer // 媒体文件 Buffer
  },
})

公众号云调用支持的接口列表一览

云调用 API 服务端接口 HTTP URL
officialAccount.user.getList https://api.weixin.qq.com/cgi-bin/user/get
officialAccount.tags.create https://api.weixin.qq.com/cgi-bin/tags/create
officialAccount.tags.get https://api.weixin.qq.com/cgi-bin/tags/get
officialAccount.tags.update https://api.weixin.qq.com/cgi-bin/tags/update
officialAccount.tags.delete https://api.weixin.qq.com/cgi-bin/tags/create
officialAccount.tags.getUsers https://api.weixin.qq.com/cgi-bin/user/tag/get
officialAccount.tags.batchTagging https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging
officialAccount.tags.batchUntagging https://api.weixin.qq.com/cgi-bin/members/batchuntagging
officialAccount.tags.getUserTagList https://api.weixin.qq.com/cgi-bin/tags/getidlist
officialAccount.user.updateRemark https://api.weixin.qq.com/cgi-bin/user/info/updateremark
officialAccount.user.getInfo https://api.weixin.qq.com/cgi-bin/user/info
officialAccount.user.batchGetInfo https://api.weixin.qq.com/cgi-bin/user/info/batchget
officialAccount.user.getBlacklist https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist
officialAccount.tags.batchUnblacklist https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist
officialAccount.media.upload https://api.weixin.qq.com/cgi-bin/media/upload
officialAccount.media.get https://api.weixin.qq.com/cgi-bin/media/get
officialAccount.media.getFromJSSDK https://api.weixin.qq.com/cgi-bin/media/get/jssdk
officialAccount.material.addNews https://api.weixin.qq.com/cgi-bin/material/add_news
officialAccount.media.uploadImg https://api.weixin.qq.com/cgi-bin/media/uploadimg
officialAccount.material.addMaterial https://api.weixin.qq.com/cgi-bin/material/add_material
officialAccount.material.get https://api.weixin.qq.com/cgi-bin/material/get_material
officialAccount.material.delelete https://api.weixin.qq.com/cgi-bin/material/del_material
officialAccount.material.updateNews https://api.weixin.qq.com/cgi-bin/material/update_news
officialAccount.material.getMaterialCount https://api.weixin.qq.com/cgi-bin/material/get_materialcount
officialAccount.material.batchGetMaterial https://api.weixin.qq.com/cgi-bin/material/batchget_material
officialAccount.comment.open https://api.weixin.qq.com/cgi-bin/comment/open
officialAccount.comment.close https://api.weixin.qq.com/cgi-bin/comment/close
officialAccount.comment.list https://api.weixin.qq.com/cgi-bin/comment/list
officialAccount.comment.markElect https://api.weixin.qq.com/cgi-bin/comment/markelect
officialAccount.comment.unmarkElect https://api.weixin.qq.com/cgi-bin/comment/unmarkelect
officialAccount.comment.delete https://api.weixin.qq.com/cgi-bin/comment/delete
officialAccount.comment.reply https://api.weixin.qq.com/cgi-bin/comment/reply/add
officialAccount.comment.deleteReply https://api.weixin.qq.com/cgi-bin/comment/reply/delete
officialAccount.qrcode.create https://api.weixin.qq.com/cgi-bin/qrcode/create
officialAccount.shorturl https://api.weixin.qq.com/cgi-bin/shorturl
officialAccount.datacube.getUserSummary https://api.weixin.qq.com/datacube/getusersummary
officialAccount.datacube.getUserCumulate https://api.weixin.qq.com/datacube/getusercumulate
officialAccount.datacube.getArticleSummary https://api.weixin.qq.com/datacube/getarticlesummary
officialAccount.datacube.getArticleTotal https://api.weixin.qq.com/datacube/getarticletotal
officialAccount.datacube.getUserRead https://api.weixin.qq.com/datacube/getuserread
officialAccount.datacube.getUserReadHour https://api.weixin.qq.com/datacube/getuserreadhour
officialAccount.datacube.getUserShare https://api.weixin.qq.com/datacube/getusershare
officialAccount.datacube.getUserShareHour https://api.weixin.qq.com/datacube/getusersharehour
officialAccount.datacube.getUpstreamMsg https://api.weixin.qq.com/datacube/getupstreammsg
officialAccount.datacube.getUpstreamMsgHour https://api.weixin.qq.com/datacube/getupstreammsghour
officialAccount.datacube.getUpstreamMsgWeek https://api.weixin.qq.com/datacube/getupstreammsgweek
officialAccount.datacube.getUpstreamMsgMonth https://api.weixin.qq.com/datacube/getupstreammsgmonth
officialAccount.datacube.getUpstreamMsgDist https://api.weixin.qq.com/datacube/getupstreammsgdist
officialAccount.datacube.getUpstreamMsgDistWeek https://api.weixin.qq.com/datacube/getupstreammsgdistweek
officialAccount.datacube.getUpstreamMsgDistMonth https://api.weixin.qq.com/datacube/getupstreammsgdistmonth
officialAccount.publisher.stat https://api.weixin.qq.com/publisher/stat
officialAccount.datacube.getInterfaceSummary https://api.weixin.qq.com/datacube/getinterfacesummary
officialAccount.datacube.getInterfaceSummaryHour https://api.weixin.qq.com/datacube/getinterfacesummaryhour
officialAccount.card.create https://api.weixin.qq.com/card/create
officialAccount.card.setPayCell https://api.weixin.qq.com/card/paycell/set
officialAccount.card.setSelfConsumeCell https://api.weixin.qq.com/card/selfconsumecell/set
officialAccount.card.createQRCode https://api.weixin.qq.com/card/qrcode/create
officialAccount.card.createLandingPage https://api.weixin.qq.com/card/landingpage/create
officialAccount.card.depositCode https://api.weixin.qq.com/card/code/deposit
officialAccount.card.getDepositCodeCount https://api.weixin.qq.com/card/code/getdepositcount
officialAccount.card.getNewsHTML https://api.weixin.qq.com/card/mpnews/gethtml
officialAccount.card.setTestWhitelist https://api.weixin.qq.com/card/testwhitelist/set
officialAccount.card.getCode https://api.weixin.qq.com/card/code/get
officialAccount.card.consumeCode https://api.weixin.qq.com/card/code/consume
officialAccount.card.decryptCode https://api.weixin.qq.com/card/code/decrypt
officialAccount.card.getUserCardList https://api.weixin.qq.com/card/user/getcardlist
officialAccount.card.get https://api.weixin.qq.com/card/get
officialAccount.card.batchGet https://api.weixin.qq.com/card/batchget
officialAccount.card.update https://api.weixin.qq.com/card/update
officialAccount.card.modifyStock https://api.weixin.qq.com/card/modifystock
officialAccount.card.updateCode https://api.weixin.qq.com/card/code/update
officialAccount.card.invalidateCode https://api.weixin.qq.com/card/code/unavailable
officialAccount.datacube.getCardBizInfo https://api.weixin.qq.com/datacube/getcardbizuininfo
officialAccount.datacube.getFreeCardInfo https://api.weixin.qq.com/datacube/getcardcardinfo
officialAccount.datacube.getMemberCardInfo https://api.weixin.qq.com/datacube/getcardmembercardinfo
officialAccount.datacube.getMemberCardDetail https://api.weixin.qq.com/datacube/getcardmembercarddetail
officialAccount.card.addGiftCard https://api.weixin.qq.com/card/giftcard/page/add
officialAccount.card.getGiftCard https://api.weixin.qq.com/card/giftcard/page/get
officialAccount.card.updateGiftCard https://api.weixin.qq.com/card/giftcard/page/update
officialAccount.card.batchGetGiftCard https://api.weixin.qq.com/card/giftcard/page/batchget
officialAccount.card.maintainGiftCard https://api.weixin.qq.com/card/giftcard/maintain/set
officialAccount.card.addGiftCardPayWhitelist https://api.weixin.qq.com/card/giftcard/pay/whitelist/add
officialAccount.card.bindSubMchGiftCardPay https://api.weixin.qq.com/card/giftcard/pay/submch/bind
officialAccount.card.setWXAGiftCard https://api.weixin.qq.com/card/giftcard/wxa/set
officialAccount.card.getGiftCardOrder https://api.weixin.qq.com/card/giftcard/order/get
officialAccount.card.batchGetGiftCardOrder https://api.weixin.qq.com/card/giftcard/order/batchget
officialAccount.card.updateUserCard https://api.weixin.qq.com/card/generalcard/updateuser
officialAccount.card.refundGiftCardOrder https://api.weixin.qq.com/card/giftcard/order/refund
officialAccount.card.invoiceInfo https://api.weixin.qq.com/card/invoice/setbizattr
officialAccount.card.getInvoiceAuthData https://api.weixin.qq.com/card/invoice/getauthdata
officialAccount.card.activateMemberCard https://api.weixin.qq.com/card/membercard/activate
officialAccount.card.setMemberCardActivateUserForm https://api.weixin.qq.com/card/membercard/activateuserform/set
officialAccount.card.getMemberCardUserInfo https://api.weixin.qq.com/card/membercard/userinfo/get
officialAccount.card.getMemberCardActivateTempInfo https://api.weixin.qq.com/card/membercard/activatetempinfo/get
officialAccount.card.updateMemberCardUserInfo https://api.weixin.qq.com/card/membercard/updateuser
officialAccount.card.getMemberCardUserInfo https://api.weixin.qq.com/card/membercard/userinfo/get
officialAccount.addPayGiftCard https://api.weixin.qq.com/card/paygiftcard/add
officialAccount.deletePayGiftCard https://api.weixin.qq.com/card/paygiftcard/delete
officialAccount.card.GetPayGiftCardById https://api.weixin.qq.com/card/paygiftcard/getbyid
officialAccount.card.batchGetPayGiftCard https://api.weixin.qq.com/card/paygiftcard/batchget
officialAccount.card.updateMeetingTicket https://api.weixin.qq.com/card/meetingticket/updateuser
officialAccount.card.updateMovieTicket https://api.weixin.qq.com/card/movieticket/updateuser
officialAccount.card.update.updateBoardingPass https://api.weixin.qq.com/card/boardingpass/checkin
officialAccount.card.submitSubmerchant https://api.weixin.qq.com/card/submerchant/submit
officialAccount.card.getApplyProtocol https://api.weixin.qq.com/card/getapplyprotocol
officialAccount.card.updateSubmerchant https://api.weixin.qq.com/card/submerchant/update
officialAccount.card.getSubmerchant https://api.weixin.qq.com/card/submerchant/get
officialAccount.card.batchGetSubmerchant https://api.weixin.qq.com/card/submerchant/batchget
officialAccount.poi.add https://api.weixin.qq.com/cgi-bin/poi/addpoi
officialAccount.poi.get https://api.weixin.qq.com/cgi-bin/poi/getpoi
officialAccount.poi.getList https://api.weixin.qq.com/cgi-bin/poi/getpoilist
officialAccount.poi.update https://api.weixin.qq.com/poi/updatepoi
officialAccount.poi.delete https://api.weixin.qq.com/cgi-bin/poi/delpoi
officialAccount.poi.getWXCategory https://api.weixin.qq.com/cgi-bin/poi/getwxcategory
officialAccount.mpStore.getCategory https://api.weixin.qq.com/wxa/get_merchant_category
officialAccount.mpStore.apply https://api.weixin.qq.com/wxa/apply_merchant
officialAccount.mpStore.getAuditInfo https://api.weixin.qq.com/wxa/get_merchant_audit_info
officialAccount.mpStore.modify https://api.weixin.qq.com/wxa/modify_merchant
officialAccount.map.getDistrict https://api.weixin.qq.com/wxa/get_district
officialAccount.map.searchPoi https://api.weixin.qq.com/wxa/search_map_poi
officialAccount.map.createPoi https://api.weixin.qq.com/wxa/create_map_poi
officialAccount.mpStore.addStore https://api.weixin.qq.com/wxa/add_store
officialAccount.mpStore.updateStore https://api.weixin.qq.com/wxa/update_store
officialAccount.mpStore.getStoreInfo https://api.weixin.qq.com/wxa/get_store_info
officialAccount.mpStore.getStoreList https://api.weixin.qq.com/wxa/get_store_list
officialAccount.mpStore.deleteStore https://api.weixin.qq.com/wxa/del_store
officialAccount.mpStore.getCard https://api.weixin.qq.com/card/storewxa/get
officialAccount.mpStore.setCard https://api.weixin.qq.com/card/storewxa/set
officialAccount.semantic.search https://api.weixin.qq.com/semantic/semproxy/search
officialAccount.voice.uploadVoiceForText https://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext
officialAccount.voice.queryVoiceTextResult https://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext
officialAccount.voice.translateContent https://api.weixin.qq.com/voice/translatecontent
officialAccount.customerService.getList https://api.weixin.qq.com/cgi-bin/customservice/getkflist
officialAccount.customerService.getOnlineList https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist
officialAccount.customerService.addKFAccount https://api.weixin.qq.com/customservice/kfaccount/add
officialAccount.customerService.inviteWorker https://api.weixin.qq.com/customservice/kfaccount/inviteworker
officialAccount.customerService.updateKFAccount https://api.weixin.qq.com/customservice/kfaccount/update
officialAccount.customerService.uploadHeadImg https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg
officialAccount.customerService.deleteKFAccount https://api.weixin.qq.com/customservice/kfaccount/del
officialAccount.customerService.createKFSession https://api.weixin.qq.com/customservice/kfsession/create
officialAccount.customerService.closeKFSession https://api.weixin.qq.com/customservice/kfsession/close
officialAccount.customerService.getKFSession https://api.weixin.qq.com/customservice/kfsession/getsession
officialAccount.customerService.getKFSessionList https://api.weixin.qq.com/customservice/kfsession/getsessionlist
officialAccount.customerService.getKFSessionWaitCase https://api.weixin.qq.com/customservice/kfsession/getwaitcase
officialAccount.customerService.getMsgList https://api.weixin.qq.com/customservice/msgrecord/getmsglist