💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Niushop开源商城通过插件开发短信接口 --- niushop系统内置安装了阿里云短信接口,开发者可以根据自己的要求自行开发短信接口 ![](https://img.kancloud.cn/1d/64/1d643e69bd6627554c76fabd104530be_448x170.png) * **后台功能开发,实现系统配置** ``` namespace addons\NsAlisms; use addons\BaseConfig; class Config extends BaseConfig { /** * 菜单设置 */ public function menu(){ $menu = [ [ 'module_name' => '阿里云短信配置', 'controller' => 'Config', 'method' => 'alismsConfig', 'parent' => ['module' => 'admin', 'controller' => 'Config', 'method' => 'webconfig', 'level' => 2], 'url' => 'Config/alismsConfig', 'is_menu' => 0, 'is_dev' => 0, 'sort' => 9, 'desc' => '阿里云短信配置', 'module_picture' => '', 'icon_class' => '', 'is_control_auth' => 1, ] ]; return $menu; } } ``` * **钩子开发,获取短信配置smsconfig\($param\),注意配置信息** ```php public function smsconfig($param) { $alisms_config = new AlismsConfig(); $config = $alisms_config->getMobileMessage($param['instance_id']); $config["logo"] = "addons/NsAlisms/aliyun.jpg"; $config["pay_name"] = "阿里云短信"; $config["desc"] = "该系统支持短信接口"; $config['url'] = __URL('__URL__/NsAlisms/' . ADMIN_MODULE . '/Config/alismsConfig'); return $config; } ``` * **钩子开发,短信发送,注意返回数据结构,包括code,message,param** ```php /** * 短信发送(短信插件实现接口) * @param unknown $param 说明传入参数 signName(短信签名) smsParam(短信变量赋值json) mobile(手机号) code(模板id) * @return string|multitype:number string |multitype:number unknown Ambigous <number, string, unknown, NULL> */ public function smssend($param) { $alisms_config = new AlismsConfig(); $config = $alisms_config->getMobileMessage(0); if ($config['is_use'] == 0) { return ''; } if (empty($config['value']['appKey']) || empty($config['value']['secretKey']) || empty($config['value']['freeSignName']) || empty($config['is_use'])) { return [ 'code' => -1, 'message' => "短信配置信息有误!", 'param' => 0 ]; } $result = $alisms_config->aliSmsSend($config['value']['appKey'], $config['value']['secretKey'], $param['signName'], $param['smsParam'], $param['mobile'], $param['code'], $config['value']['user_type']); $result = $this->dealAliSmsResult($result); return [ 'code' => $result["code"], 'message' => $result["message"], 'param' => rand(100000, 999999) ]; } ```