公众号云调用

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

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

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

示例 1:JSON POST

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

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

示例 2:FORM POST

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

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

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

云调用 API服务端接口 HTTP URL
officialAccount.user.getListhttps://api.weixin.qq.com/cgi-bin/user/get
officialAccount.tags.createhttps://api.weixin.qq.com/cgi-bin/tags/create
officialAccount.tags.gethttps://api.weixin.qq.com/cgi-bin/tags/get
officialAccount.tags.updatehttps://api.weixin.qq.com/cgi-bin/tags/update
officialAccount.tags.deletehttps://api.weixin.qq.com/cgi-bin/tags/create
officialAccount.tags.getUsershttps://api.weixin.qq.com/cgi-bin/user/tag/get
officialAccount.tags.batchTagginghttps://api.weixin.qq.com/cgi-bin/tags/members/batchtagging
officialAccount.tags.batchUntagginghttps://api.weixin.qq.com/cgi-bin/members/batchuntagging
officialAccount.tags.getUserTagListhttps://api.weixin.qq.com/cgi-bin/tags/getidlist
officialAccount.user.updateRemarkhttps://api.weixin.qq.com/cgi-bin/user/info/updateremark
officialAccount.user.getInfohttps://api.weixin.qq.com/cgi-bin/user/info
officialAccount.user.batchGetInfohttps://api.weixin.qq.com/cgi-bin/user/info/batchget
officialAccount.user.getBlacklisthttps://api.weixin.qq.com/cgi-bin/tags/members/getblacklist
officialAccount.tags.batchUnblacklisthttps://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist
officialAccount.media.uploadhttps://api.weixin.qq.com/cgi-bin/media/upload
officialAccount.media.gethttps://api.weixin.qq.com/cgi-bin/media/get
officialAccount.media.getFromJSSDKhttps://api.weixin.qq.com/cgi-bin/media/get/jssdk
officialAccount.material.addNewshttps://api.weixin.qq.com/cgi-bin/material/add_news
officialAccount.media.uploadImghttps://api.weixin.qq.com/cgi-bin/media/uploadimg
officialAccount.material.addMaterialhttps://api.weixin.qq.com/cgi-bin/material/add_material
officialAccount.material.gethttps://api.weixin.qq.com/cgi-bin/material/get_material
officialAccount.material.deleletehttps://api.weixin.qq.com/cgi-bin/material/del_material
officialAccount.material.updateNewshttps://api.weixin.qq.com/cgi-bin/material/update_news
officialAccount.material.getMaterialCounthttps://api.weixin.qq.com/cgi-bin/material/get_materialcount
officialAccount.material.batchGetMaterialhttps://api.weixin.qq.com/cgi-bin/material/batchget_material
officialAccount.comment.openhttps://api.weixin.qq.com/cgi-bin/comment/open
officialAccount.comment.closehttps://api.weixin.qq.com/cgi-bin/comment/close
officialAccount.comment.listhttps://api.weixin.qq.com/cgi-bin/comment/list
officialAccount.comment.markElecthttps://api.weixin.qq.com/cgi-bin/comment/markelect
officialAccount.comment.unmarkElecthttps://api.weixin.qq.com/cgi-bin/comment/unmarkelect
officialAccount.comment.deletehttps://api.weixin.qq.com/cgi-bin/comment/delete
officialAccount.comment.replyhttps://api.weixin.qq.com/cgi-bin/comment/reply/add
officialAccount.comment.deleteReplyhttps://api.weixin.qq.com/cgi-bin/comment/reply/delete
officialAccount.qrcode.createhttps://api.weixin.qq.com/cgi-bin/qrcode/create
officialAccount.shorturlhttps://api.weixin.qq.com/cgi-bin/shorturl
officialAccount.datacube.getUserSummaryhttps://api.weixin.qq.com/datacube/getusersummary
officialAccount.datacube.getUserCumulatehttps://api.weixin.qq.com/datacube/getusercumulate
officialAccount.datacube.getArticleSummaryhttps://api.weixin.qq.com/datacube/getarticlesummary
officialAccount.datacube.getArticleTotalhttps://api.weixin.qq.com/datacube/getarticletotal
officialAccount.datacube.getUserReadhttps://api.weixin.qq.com/datacube/getuserread
officialAccount.datacube.getUserReadHourhttps://api.weixin.qq.com/datacube/getuserreadhour
officialAccount.datacube.getUserSharehttps://api.weixin.qq.com/datacube/getusershare
officialAccount.datacube.getUserShareHourhttps://api.weixin.qq.com/datacube/getusersharehour
officialAccount.datacube.getUpstreamMsghttps://api.weixin.qq.com/datacube/getupstreammsg
officialAccount.datacube.getUpstreamMsgHourhttps://api.weixin.qq.com/datacube/getupstreammsghour
officialAccount.datacube.getUpstreamMsgWeekhttps://api.weixin.qq.com/datacube/getupstreammsgweek
officialAccount.datacube.getUpstreamMsgMonthhttps://api.weixin.qq.com/datacube/getupstreammsgmonth
officialAccount.datacube.getUpstreamMsgDisthttps://api.weixin.qq.com/datacube/getupstreammsgdist
officialAccount.datacube.getUpstreamMsgDistWeekhttps://api.weixin.qq.com/datacube/getupstreammsgdistweek
officialAccount.datacube.getUpstreamMsgDistMonthhttps://api.weixin.qq.com/datacube/getupstreammsgdistmonth
officialAccount.publisher.stathttps://api.weixin.qq.com/publisher/stat
officialAccount.datacube.getInterfaceSummaryhttps://api.weixin.qq.com/datacube/getinterfacesummary
officialAccount.datacube.getInterfaceSummaryHourhttps://api.weixin.qq.com/datacube/getinterfacesummaryhour
officialAccount.card.createhttps://api.weixin.qq.com/card/create
officialAccount.card.setPayCellhttps://api.weixin.qq.com/card/paycell/set
officialAccount.card.setSelfConsumeCellhttps://api.weixin.qq.com/card/selfconsumecell/set
officialAccount.card.createQRCodehttps://api.weixin.qq.com/card/qrcode/create
officialAccount.card.createLandingPagehttps://api.weixin.qq.com/card/landingpage/create
officialAccount.card.depositCodehttps://api.weixin.qq.com/card/code/deposit
officialAccount.card.getDepositCodeCounthttps://api.weixin.qq.com/card/code/getdepositcount
officialAccount.card.getNewsHTMLhttps://api.weixin.qq.com/card/mpnews/gethtml
officialAccount.card.setTestWhitelisthttps://api.weixin.qq.com/card/testwhitelist/set
officialAccount.card.getCodehttps://api.weixin.qq.com/card/code/get
officialAccount.card.consumeCodehttps://api.weixin.qq.com/card/code/consume
officialAccount.card.decryptCodehttps://api.weixin.qq.com/card/code/decrypt
officialAccount.card.getUserCardListhttps://api.weixin.qq.com/card/user/getcardlist
officialAccount.card.gethttps://api.weixin.qq.com/card/get
officialAccount.card.batchGethttps://api.weixin.qq.com/card/batchget
officialAccount.card.updatehttps://api.weixin.qq.com/card/update
officialAccount.card.modifyStockhttps://api.weixin.qq.com/card/modifystock
officialAccount.card.updateCodehttps://api.weixin.qq.com/card/code/update
officialAccount.card.invalidateCodehttps://api.weixin.qq.com/card/code/unavailable
officialAccount.datacube.getCardBizInfohttps://api.weixin.qq.com/datacube/getcardbizuininfo
officialAccount.datacube.getFreeCardInfohttps://api.weixin.qq.com/datacube/getcardcardinfo
officialAccount.datacube.getMemberCardInfohttps://api.weixin.qq.com/datacube/getcardmembercardinfo
officialAccount.datacube.getMemberCardDetailhttps://api.weixin.qq.com/datacube/getcardmembercarddetail
officialAccount.card.addGiftCardhttps://api.weixin.qq.com/card/giftcard/page/add
officialAccount.card.getGiftCardhttps://api.weixin.qq.com/card/giftcard/page/get
officialAccount.card.updateGiftCardhttps://api.weixin.qq.com/card/giftcard/page/update
officialAccount.card.batchGetGiftCardhttps://api.weixin.qq.com/card/giftcard/page/batchget
officialAccount.card.maintainGiftCardhttps://api.weixin.qq.com/card/giftcard/maintain/set
officialAccount.card.addGiftCardPayWhitelisthttps://api.weixin.qq.com/card/giftcard/pay/whitelist/add
officialAccount.card.bindSubMchGiftCardPayhttps://api.weixin.qq.com/card/giftcard/pay/submch/bind
officialAccount.card.setWXAGiftCardhttps://api.weixin.qq.com/card/giftcard/wxa/set
officialAccount.card.getGiftCardOrderhttps://api.weixin.qq.com/card/giftcard/order/get
officialAccount.card.batchGetGiftCardOrderhttps://api.weixin.qq.com/card/giftcard/order/batchget
officialAccount.card.updateUserCardhttps://api.weixin.qq.com/card/generalcard/updateuser
officialAccount.card.refundGiftCardOrderhttps://api.weixin.qq.com/card/giftcard/order/refund
officialAccount.card.invoiceInfohttps://api.weixin.qq.com/card/invoice/setbizattr
officialAccount.card.getInvoiceAuthDatahttps://api.weixin.qq.com/card/invoice/getauthdata
officialAccount.card.activateMemberCardhttps://api.weixin.qq.com/card/membercard/activate
officialAccount.card.setMemberCardActivateUserFormhttps://api.weixin.qq.com/card/membercard/activateuserform/set
officialAccount.card.getMemberCardUserInfohttps://api.weixin.qq.com/card/membercard/userinfo/get
officialAccount.card.getMemberCardActivateTempInfohttps://api.weixin.qq.com/card/membercard/activatetempinfo/get
officialAccount.card.updateMemberCardUserInfohttps://api.weixin.qq.com/card/membercard/updateuser
officialAccount.card.getMemberCardUserInfohttps://api.weixin.qq.com/card/membercard/userinfo/get
officialAccount.addPayGiftCardhttps://api.weixin.qq.com/card/paygiftcard/add
officialAccount.deletePayGiftCardhttps://api.weixin.qq.com/card/paygiftcard/delete
officialAccount.card.GetPayGiftCardByIdhttps://api.weixin.qq.com/card/paygiftcard/getbyid
officialAccount.card.batchGetPayGiftCardhttps://api.weixin.qq.com/card/paygiftcard/batchget
officialAccount.card.updateMeetingTickethttps://api.weixin.qq.com/card/meetingticket/updateuser
officialAccount.card.updateMovieTickethttps://api.weixin.qq.com/card/movieticket/updateuser
officialAccount.card.update.updateBoardingPasshttps://api.weixin.qq.com/card/boardingpass/checkin
officialAccount.card.submitSubmerchanthttps://api.weixin.qq.com/card/submerchant/submit
officialAccount.card.getApplyProtocolhttps://api.weixin.qq.com/card/getapplyprotocol
officialAccount.card.updateSubmerchanthttps://api.weixin.qq.com/card/submerchant/update
officialAccount.card.getSubmerchanthttps://api.weixin.qq.com/card/submerchant/get
officialAccount.card.batchGetSubmerchanthttps://api.weixin.qq.com/card/submerchant/batchget
officialAccount.poi.addhttps://api.weixin.qq.com/cgi-bin/poi/addpoi
officialAccount.poi.gethttps://api.weixin.qq.com/cgi-bin/poi/getpoi
officialAccount.poi.getListhttps://api.weixin.qq.com/cgi-bin/poi/getpoilist
officialAccount.poi.updatehttps://api.weixin.qq.com/poi/updatepoi
officialAccount.poi.deletehttps://api.weixin.qq.com/cgi-bin/poi/delpoi
officialAccount.poi.getWXCategoryhttps://api.weixin.qq.com/cgi-bin/poi/getwxcategory
officialAccount.mpStore.getCategoryhttps://api.weixin.qq.com/wxa/get_merchant_category
officialAccount.mpStore.applyhttps://api.weixin.qq.com/wxa/apply_merchant
officialAccount.mpStore.getAuditInfohttps://api.weixin.qq.com/wxa/get_merchant_audit_info
officialAccount.mpStore.modifyhttps://api.weixin.qq.com/wxa/modify_merchant
officialAccount.map.getDistricthttps://api.weixin.qq.com/wxa/get_district
officialAccount.map.searchPoihttps://api.weixin.qq.com/wxa/search_map_poi
officialAccount.map.createPoihttps://api.weixin.qq.com/wxa/create_map_poi
officialAccount.mpStore.addStorehttps://api.weixin.qq.com/wxa/add_store
officialAccount.mpStore.updateStorehttps://api.weixin.qq.com/wxa/update_store
officialAccount.mpStore.getStoreInfohttps://api.weixin.qq.com/wxa/get_store_info
officialAccount.mpStore.getStoreListhttps://api.weixin.qq.com/wxa/get_store_list
officialAccount.mpStore.deleteStorehttps://api.weixin.qq.com/wxa/del_store
officialAccount.mpStore.getCardhttps://api.weixin.qq.com/card/storewxa/get
officialAccount.mpStore.setCardhttps://api.weixin.qq.com/card/storewxa/set
officialAccount.semantic.searchhttps://api.weixin.qq.com/semantic/semproxy/search
officialAccount.voice.uploadVoiceForTexthttps://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext
officialAccount.voice.queryVoiceTextResulthttps://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext
officialAccount.voice.translateContenthttps://api.weixin.qq.com/voice/translatecontent
officialAccount.customerService.getListhttps://api.weixin.qq.com/cgi-bin/customservice/getkflist
officialAccount.customerService.getOnlineListhttps://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist
officialAccount.customerService.addKFAccounthttps://api.weixin.qq.com/customservice/kfaccount/add
officialAccount.customerService.inviteWorkerhttps://api.weixin.qq.com/customservice/kfaccount/inviteworker
officialAccount.customerService.updateKFAccounthttps://api.weixin.qq.com/customservice/kfaccount/update
officialAccount.customerService.uploadHeadImghttps://api.weixin.qq.com/customservice/kfaccount/uploadheadimg
officialAccount.customerService.deleteKFAccounthttps://api.weixin.qq.com/customservice/kfaccount/del
officialAccount.customerService.createKFSessionhttps://api.weixin.qq.com/customservice/kfsession/create
officialAccount.customerService.closeKFSessionhttps://api.weixin.qq.com/customservice/kfsession/close
officialAccount.customerService.getKFSessionhttps://api.weixin.qq.com/customservice/kfsession/getsession
officialAccount.customerService.getKFSessionListhttps://api.weixin.qq.com/customservice/kfsession/getsessionlist
officialAccount.customerService.getKFSessionWaitCasehttps://api.weixin.qq.com/customservice/kfsession/getwaitcase
officialAccount.customerService.getMsgListhttps://api.weixin.qq.com/customservice/msgrecord/getmsglist