Option::get("platform_third_appid", 0, 'saas')['value'], //微信三方appSecret 'secret' => Option::get("platform_third_secret", 0, 'saas')['value'], //微信三方平台设置的token 'token' => Option::get("platform_token", 0, 'saas')['value'], //微信三方平台设置的加密key 'aes_key' => Option::get("platform_encodingAesKey", 0, 'saas')['value'] ]; $this->openPlatform = Factory::openPlatform($wx_config); } /** * 微信业务实现 */ public function miniProgram ($appid = "") { try { $store_id = $this->store_id; //获取小程序信息 $store_mini = StoreMini::find()->where( ['or', ['id' => $this->mini_id], ['appid' => $appid, 'store_id' => $store_id], ['store_id' => $store_id] ])->orderBy('id desc')->one(); if (empty($store_mini->appid) || empty($store_mini->authorizer_refresh_token)) { throw new \Exception("获取小程序信息失败"); } //配置easyWechat return $this->openPlatform->miniProgram($store_mini->appid, $store_mini->authorizer_refresh_token); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //获取网络图片到临时目录 public function saveTempImage($url) { if (strpos($url, 'http') === false) { $url = 'http:' . trim($url); } if (!is_dir(\Yii::$app->runtimePath . '/image')) { mkdir(\Yii::$app->runtimePath . '/image'); } $save_path = \Yii::$app->runtimePath . '/image/' . md5($url) . '.jpg'; CurlHelper::download($url, $save_path); return $save_path; } //递归 public function getdata($data, $id = [0]) { foreach ($data as $k => $v) { if (in_array($v['id'], $id)) { $v['children'] = $this->getdata($data, $v['children']); $arr[] = $v; } } return $arr; } //返回中文错误信息 public function getZnMsg($result) { $ErrorMsg = new ErrorMsg(); $arr = $ErrorMsg->getArray(); $msg = !empty($arr[$result['errcode']]) ? $arr[$result['errcode']] : $result['errmsg']; return $msg; } }