docs/src/5.x/mini-program/business.md
小程序商户功能允许小程序接入商户能力,为小程序提供商户服务相关的接口。
$business = $app->business;
注册商户账号:
$result = $business->register('商户账号名', '商户昵称', '头像媒体ID');
参数说明:
accountName string 商户账号名nickname string 商户昵称iconMediaId string 头像媒体ID可以通过商户ID或账号名获取商户信息:
// 通过商户ID获取
$result = $business->getBusiness($businessId);
// 通过账号名获取
$result = $business->getBusiness(0, 'account_name');
参数说明:
businessId int 商户IDaccountName string 商户账号名获取商户列表,支持分页:
$result = $business->list($offset, $count);
参数说明:
offset int 偏移量,默认为0count int 返回数量,默认为10更新商户昵称和头像:
$result = $business->update($businessId, '新昵称', '新头像媒体ID');
参数说明:
businessId int 商户IDnickname string 新昵称(可选)iconMediaId string 新头像媒体ID(可选)$message = $business->message('消息内容');
$message = [
'touser' => 'openid',
'msgtype' => 'text',
'text' => [
'content' => '消息内容'
],
'business_id' => $businessId
];
$result = $business->send($message);
显示"正在输入"状态:
$result = $business->typing($businessId, $toUser);
参数说明:
businessId int 商户IDtoUser string 用户openiduse EasyWeChat\Factory;
$config = [
'app_id' => 'your-app-id',
'secret' => 'your-app-secret',
// ...
];
$app = Factory::miniProgram($config);
$business = $app->business;
// 注册商户
$result = $business->register('test_merchant', '测试商户', 'media_id_123');
if ($result['errcode'] === 0) {
$businessId = $result['business_id'];
// 发送消息
$message = [
'touser' => 'user_openid',
'msgtype' => 'text',
'text' => [
'content' => '欢迎使用商户服务!'
],
'business_id' => $businessId
];
$business->send($message);
}