微信小程序組件 1.2.x
獲取小程序?qū)ο?/h3>
$wxa = new \EasySwoole\WeChat\MiniProgram\MiniProgram;
$wxa->getConfig()->setAppId('your appid')->setAppSecret('your appsecret');
獲取小程序session
$wxa = new \EasySwoole\WeChat\MiniProgram\MiniProgram;
$wxa->getConfig()->setAppId('your appid')->setAppSecret('your appsecret');
詳細(xì)信息請參閱 微信小程序登陸
$code = '';
$session = $wxa->auth()->session($code);
你會返回一個(gè)包含下面文檔中提到的參數(shù)的數(shù)組 code2Session
創(chuàng)建二維碼
參閱文檔documentation
我們可以使用一下三種方式創(chuàng)建二維碼
/** 二維碼 - 永久小程序碼 Api: $wxa->qrCode()->getWxaCode()
* @param $path 掃碼進(jìn)入的小程序頁面路徑,最大長度 128 字節(jié)
* @param int $width 二維碼的寬度
* @param bool $autoColor 自動(dòng)配置線條顏色
* @param null $lineColor auto_color 為 false 時(shí)生效,使用 rgb 設(shè)置顏色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十進(jìn)制表示
* @param bool $isHyaline 是否需要透明底色
*/
function getWxaCode($path, $width = 430, $autoColor = false, $lineColor = null, $isHyaline = false)
/**
* 二維碼 - 臨時(shí)小程序碼 Api: $wxa->qrCode()->getWxaCodeUnLimit()
* @param $path 已經(jīng)發(fā)布的小程序存在的頁面
* @param $scene 最大32個(gè)可見字符
* @param int $width 二維碼的寬度
* @param bool $autoColor 自動(dòng)配置線條顏色
* @param null $lineColor auto_color 為 false 時(shí)生效,使用 rgb 設(shè)置顏色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十進(jìn)制表示
* @param bool $isHyaline 是否需要透明底色
*/
function getWxaCodeUnLimit($path, $scene, $width = 430, $autoColor = false, $lineColor = null, $isHyaline = false)
/**
* 二維碼 - 永久二維碼 Api: $wxa->qrCode()->createWxaQrCode()
* @param $path 掃碼進(jìn)入的小程序頁面路徑,最大長度 128 字節(jié)
* @param int $width 二維碼的寬度
*/
function createWxaQrCode($path, $width = 430)
獲取帳號下已存在的模板列表
$wxa->templateMsg()->getTemplateList(int $offset, int $count)
獲取模板庫某個(gè)模板標(biāo)題下關(guān)鍵詞庫
$wxa->templateMsg()->getTemplateLibraryById(string $id)
組合模板并添加至帳號下的個(gè)人模板庫
$wxa->templateMsg()->addTemplate(string $id, array $keywordIdList)
刪除帳號下的某個(gè)模板
$wxa->templateMsg()->deleteTemplate(string $templateId)
獲取小程序模板庫標(biāo)題列表
$wxa->templateMsg()->getTemplateLibraryList(int $offset, int $count)
發(fā)送模板消息
//要傳遞的參數(shù)數(shù)組,下面實(shí)際方法中是傳入Bean
$templateMsg = [
'touser' => 'user-openid',
'template_id' => 'template-id',
'page' => 'index',
'form_id' => 'form-id',
'data' => [
'keyword1' => 'VALUE',
'keyword2' => 'VALUE2',
],
];
$wxa->templateMsg()->send(TemplateMsgBean $templateMsg)
微信小程序消息解密(獲取電話等功能,信息是加密的,需要解密)
$wxa->encryptor()->decryptData(string $sessionKey, string $iv, string $encryptedData)
檢查一段文本是否含有違法違規(guī)內(nèi)容
$wxa->checkFile()->msgSecCheck(string $content)
校驗(yàn)一張圖片是否含有違法違規(guī)內(nèi)容
$wxa->checkFile()->imgSecCheck(ImgUploadBean $imgUpload)
異步校驗(yàn)圖片/音頻是否含有違法違規(guī)內(nèi)容
$wxa->checkFile()->mediaCheckAsync(string $mediaUrl ,int $mediaType)
物流助手(小程序)
/**
* 綁定、解綁物流賬號 Api: $wxa->logisticsProgram()->bindAccount()
* @param BindAccount $bindAccount
*/
function bindAccount(BindAccount $bindAccount)
//例子
//要傳遞的參數(shù)數(shù)組,下面實(shí)際方法中是傳入Bean
$bindAccount = [
'type' => 'bind', //bind表示綁定,unbind表示解除綁定
'biz_id' => '1', //快遞公司客戶編碼
'delivery_id' => '1', //快遞公司ID
'password' => '***', //快遞公司客戶密碼
'remark_content'=> '測試' //備注內(nèi)容(提交EMS審核需要)
];
$wxa->logisticsProgram()->bindAccount($bindAccount);
/**獲取所有綁定的物流賬號 Api: $wxa->logisticsProgram()->getAllAccount()
*
*/
function getAllAccount()
/**
* 獲取電子面單余額。僅在使用加盟類快遞公司時(shí),才可以調(diào)用。 Api: $wxa->logisticsProgram()->getQuota()
* @param string $deliveryId 快遞公司ID
* @param string $bizId 快遞公司客戶編碼
*/
function getQuota(string $deliveryId ,string $bizId)
/**
* 生成運(yùn)單 Api: $wxa->logisticsProgram()->addOrder()
* @param AddOrder $addOrder
* 具體參數(shù)請參考文檔: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.addOrder.html
*/
function addOrder(AddOrder $addOrder)
/**
* 取消運(yùn)單 Api: $wxa->logisticsProgram()->cancelOrder()
* @param string $orderId 訂單 ID,需保證全局唯一
* @param string $openid 用戶openid,當(dāng)add_source=2時(shí)無需填寫(不發(fā)送物流服務(wù)通知)
* @param string $deliveryId 快遞公司ID
* @param string $waybillId 運(yùn)單ID
*/
function cancelOrder(string $orderId ,string $openid ,string $deliveryId ,string $waybillId)
/**
* 獲取支持的快遞公司列表 Api: $wxa->logisticsProgram()->getAllDelivery()
*/
function getAllDelivery()
/* 獲取運(yùn)單數(shù)據(jù) Api: $wxa->logisticsProgram()->getOrder()
* @param string $orderId 訂單 ID,需保證全局唯一
* @param string $openid 用戶openid,當(dāng)add_source=2時(shí)無需填寫(不發(fā)送物流服務(wù)通知)
* @param string $deliveryId 快遞公司ID
* @param string $waybillId 運(yùn)單ID
*/
function getOrder(string $orderId ,string $openid ,string $deliveryId ,string $waybillId)
/* 查詢運(yùn)單軌跡 Api: $wxa->logisticsProgram()->getPath()
* @param string $orderId 訂單 ID,需保證全局唯一
* @param string $openid 用戶openid,當(dāng)add_source=2時(shí)無需填寫(不發(fā)送物流服務(wù)通知)
* @param string $deliveryId 快遞公司ID
* @param string $waybillId 運(yùn)單ID
*/
function getPath(string $orderId ,string $openid ,string $deliveryId ,string $waybillId)
//獲取打印員。若需要使用微信打單 PC 軟件,才需要調(diào)用。 Api: $wxa->logisticsProgram()->getPrinter()
function getPrinter()
/**
* 配置面單打印員,若需要使用微信打單 PC 軟件,才需要調(diào)用。 Api: $wxa->logisticsProgram()->updatePrinter()
* @param string $openid 打印員 openid
* @param string $updateType 更新類型
* @param string $tagidList 用于平臺型小程序設(shè)置入駐方的打印員面單打印權(quán)限,同一打印員最多支持10個(gè)tagid,使用逗號分隔,如填寫123,456,表示該打印員可以拉取到tagid為123和456的下的單,非平臺型小程序無需填寫該字段
*/
function updatePrinter(string $openid ,string $updateType ,string $tagidList)
物流助手(服務(wù)端)
/**
* 獲取面單聯(lián)系人信息 Api: $wxa->logisticsService()->getContact()
* @param string $tokens 商戶側(cè)下單事件中推送的 Token 字段
* @param string $waybillId 運(yùn)單 ID
*/
function getContact(string $tokens ,string $waybillId)
/**
* 預(yù)覽面單模板。用于調(diào)試面單模板使用。 Api: $wxa->logisticsService()->previewTemplate()
* @param string $waybillId 運(yùn)單 ID
* @param string $waybillTemplate 面單 HTML 模板內(nèi)容(需經(jīng) Base64 編碼)
* @param string $waybillData 面單數(shù)據(jù)
* @param AddOrder $addOrder 商戶下單數(shù)據(jù)
* 具體參數(shù)文檔地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-provider/logistics.previewTemplate.html
*/
function previewTemplate(string $waybillId ,string $waybillTemplate ,string $waybillData,AddOrder $addOrder)
/**
* 更新商戶審核結(jié)果 Api: $wxa->logisticsService()->updateBusiness()
* @param string $shopAppId 商戶的小程序AppID
* @param string $bizId 商戶賬戶
* @param int $resultCode 審核結(jié)果,0 表示審核通過,其他表示審核失敗
* @param string $resultMsg 審核錯(cuò)誤原因,僅 result_code 不等于 0 時(shí)需要設(shè)置
*/
function updateBusiness(string $shopAppId ,string $bizId ,int $resultCode ,string $resultMsg)
/**
* 更新運(yùn)單軌跡 Api: $wxa->logisticsService()->updatePath()
* @param UpdatePath $updatePath
* 具體參數(shù)文檔地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-provider/logistics.updatePath.html
*/
function updatePath(UpdatePath $updatePath)
生物認(rèn)證
/**
* SOTER 生物認(rèn)證秘鑰簽名驗(yàn)證 Api: $wxa->attest()->verifySignature()
* @param string $openid 用戶 openid
* @param string $jsonString 通過 wx.startSoterAuthentication 成功回調(diào)獲得的 resultJSON 字段
* @param string $jsonSignature 通過 wx.startSoterAuthentication 成功回調(diào)獲得的 resultJSONSignature 字段
*/
function verifySignature(string $openid ,string $jsonString ,string $jsonSignature)
插件管理
/**
*向插件開發(fā)者發(fā)起使用插件的申請 Api: $wxa->plugin()->applyPlugin()
* @param string $action 此接口下填寫 "apply"
* @param string $pluginAppid 插件 appId
* @param string $reason 申請使用理由
*/
function applyPlugin(string $action = 'apply' ,string $pluginAppid ,string $reason = '')
/**
* 獲取當(dāng)前所有插件使用方(供插件開發(fā)者調(diào)用)Api: $wxa->plugin()->getPluginDevApplyList()
* @param string $action 此接口下填寫 "dev_apply_list"
* @param int $page 要拉取第幾頁的數(shù)據(jù)
* @param int $num 每頁的記錄數(shù)
*/
function getPluginDevApplyList(string $action = 'dev_apply_list' ,int $page = 1 ,int $num = 10)
/**
* 查詢已添加的插件 Api: $wxa->plugin()->getPluginList()
* @param string $action 此接口下填寫 "list"
*/
function getPluginList(string $action = 'list')
/**
* 修改插件使用申請的狀態(tài)(供插件開發(fā)者調(diào)用)Api: $wxa->plugin()->setDevPluginApplyStatus()
* @param string $action 修改操作
* @param string $appid 使用者的 appid。同意申請時(shí)填寫。
* @param string $reason 拒絕理由。拒絕申請時(shí)填寫
*/
function setDevPluginApplyStatus(string $action ,string $appid = '' ,string $reason = '')
/**
* 刪除已添加的插件 Api: $wxa->plugin()->unbindPlugin()
* @param string $action 此接口下填寫 "unbind"
* @param string $pluginAppid 插件 appId
*/
function unbindPlugin(string $action = 'unbind' ,string $pluginAppid)
附近的小程序
/**
* 添加地點(diǎn) Api: $wxa->program()->add()
* @param ProgramBean $program
* 參數(shù)文檔: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/nearby-poi/nearbyPoi.add.html
*/
function add(ProgramBean $program)
//例子
$program = [
'kf_info' => '{"open_kf":true,"kf_headimg":"http://mmbiz.qpic.cn/mmbiz_jpg/kKMgNtnEfQzDKpLXYhgo3W3Gndl34gITqmP914zSwhajIEJzUPpx40P7R8fRe1QmicneQMhFzpZNhSLjrvU1pIA/0?wx_fmt=jpeg","kf_name":"Harden"}',
'pic_list' => '{"list":["http://mmbiz.qpic.cn/mmbiz_jpg/kKMgNtnEfQzDKpLXYhgo3W3Gndl34gITqmP914zSwhajIEJzUPpx40P7R8fRe1QmicneQMhFzpZNhSLjrvU1pIA/0?wx_fmt=jpeg","http://mmbiz.qpic.cn/mmbiz_jpg/kKMgNtnEfQzDKpLXYhgo3W3Gndl34gITRneE5FS9uYruXGMmrtmhsBySwddEWUGOibG8Ze2NT5E3Dyt79I0htNg/0?wx_fmt=jpeg"]}',
'service_infos' => '{"service_infos":[{"id":2,"type":1,"name":"快遞","appid":"wx1373169e494e0c39","path":"index"},{"id":0,"type":2,"name":"測試","appid":"wx1373169e494e0c39","path":"index"}]}',
'store_name' => '測試測試',
'contract_phone' => '1769360227',
'hour' => '00:00-11:11',
'company_name' => '測試數(shù)據(jù)啊',
'credential' => '13082741523645',
'address' => 'xxxxxxxx',
'qualification_list' => '3LaLzqiTrQcD20DlX_o-OV1-nlYMu7sdVAL7SV2PrxVyjZFZZmB3O6LPGaYXlZWq',
];
$wxa->program()->add($program);
/**
* 刪除地點(diǎn) Api: $wxa->program()->delete()
* @param string $poiId 附近地點(diǎn) ID
*/
function delete(string $poiId)
/**
* 查看地點(diǎn)列表 Api: $wxa->program()->getList()
* @param int $page 起始頁id(從1開始計(jì)數(shù))
* @param int $pageRows 每頁展示個(gè)數(shù)(最多1000個(gè))
*/
function getList(int $page = 1 ,int $pageRows)
/**
* 展示/取消展示附近小程序 Api: $wxa->program()->setShowStatus()
* @param string $poiId 附近地點(diǎn) ID
* @param int $status 是否展示 0: 不展示,1:展示
*/
function setShowStatus(string $poiId ,int $status)