0], [['qrcode_bg'], 'string'], [['font_c','type'], 'default', 'value' => 0], [['qrcode_bg'], 'default', 'value' => \Yii::$app->request->baseUrl.'/images/2.png'], [['qrcode_c'], 'in', 'range' => [0,1]] ]; } public function attributeLabels() { return [ 'qrcode_bg' => '推广海报背景图', 'avatar_w' => '头像宽度', 'avatar_x' => '头像x坐标', 'avatar_y' => '头像y坐标', 'qrcode_c' => '二维码样式', 'qrcode_w' => '二维码宽度', 'qrcode_x' => '二维码x坐标', 'qrcode_y' => '二维码y坐标', 'font_c' => '字体颜色', 'font_w' => '字体大小', 'font_x' => '字体x坐标', 'font_y' => '字体y坐标', 'type' => '海报类型', 'invite_x' => '邀请码x坐标', 'invite_y' => '邀请码y坐标' ]; } public function save() { if ($this->validate()) { if ($this->qrcode->isNewRecord) { $this->qrcode->is_delete = 0; $this->qrcode->created_at = time(); } $this->qrcode->store_id = $this->store_id; $this->qrcode->qrcode_bg = $this->qrcode_bg; $this->qrcode->preview = $this->qrcode_bg; $avatar_size = [ 'w' => $this->avatar_w, 'h' => $this->avatar_w, ]; $avatar_position = [ 'x'=>$this->avatar_x, 'y'=>$this->avatar_y ]; $qrcode_size = [ 'w' => $this->qrcode_w, 'h' => $this->qrcode_w, 'c' => ($this->qrcode_c === '0') ? 'false' : 'true' ]; $qrcode_position = [ 'x' => $this->qrcode_x, 'y' => $this->qrcode_y ]; $font_position = [ 'x' => $this->font_x, 'y' => $this->font_y ]; $font = [ 'size' => $this->font_w, 'color' => $this->font_c ]; $invite_position = [ 'x' => $this->invite_x, 'y' => $this->invite_y ]; $this->qrcode->avatar_size = Json::encode($avatar_size); $this->qrcode->avatar_position = Json::encode($avatar_position); $this->qrcode->qrcode_size = Json::encode($qrcode_size); $this->qrcode->qrcode_position = Json::encode($qrcode_position); $this->qrcode->font_position = Json::encode($font_position); $this->qrcode->font = Json::encode($font); $this->qrcode->invite_position = Json::encode($invite_position); $this->qrcode->type = $this->type; if ($this->qrcode->save()) { return [ 'code' => 0, 'msg' => '成功' ]; } else { return [ 'code' => 1, 'msg' => '网络异常' ]; } } else { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } } public function search() { $save_root = \Yii::$app->basePath . '/web/temp/'; if (!is_dir($save_root)) { mkdir($save_root); file_put_contents($save_root . '.gitignore', "*\r\n!.gitignore"); } $version = cyy_version(); $save_name = sha1("v={$version}&store_id={$this->store_id}&user_id={$this->user_id}&type=qrcode") . '.jpg'; $pic_url = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/temp/' . $save_name; $wdcp_patch = false; $wdcp_patch_file = \Yii::$app->basePath . '/patch/wdcp.json'; if (file_exists($wdcp_patch_file)) { $wdcp_patch = json_decode(file_get_contents($wdcp_patch_file), true); if ($wdcp_patch && in_array(\Yii::$app->request->hostName, $wdcp_patch)) { $wdcp_patch = true; } else { $wdcp_patch = false; } } if ($wdcp_patch) { $pic_url = str_replace('http://', 'https://', $pic_url); } if (file_exists($save_root . $save_name)) { return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'url'=>$pic_url . '?v=' . time() ] ]; } /** @var Factory $wechat */ $data = [ 'width' => 430, ]; $scene = "uid:$this->user_id"; if (!is_open_platform() || \Yii::$app->prod_is_dandianpu()) { if (\Yii::$app->prod_is_dandianpu()) { $scene = "store:$this->store_id,uid:$this->user_id"; } $wechat = self::getWechat(); if (!$wechat) { return [ 'code' => 1, 'msg' => '该功能目前仅支持支付宝小程序', ]; } \Yii::warning("GET WXAPP QRCODE:" . "scene => ".$scene." data => ".$data); $response = $wechat->app_code->getUnlimit($scene, $data); \Yii::warning($response); // 保存小程序码到文件 if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) { $response->saveAs($save_root, $save_name); //返回图片 return [ 'code' => 0, 'data' => [ 'url' => $pic_url ] ]; } else { //返回文字 return [ 'code' => 1, 'msg' => $response['errmsg'], ]; } } else { $WechatConfig = WechatConfig::findOne(['store_id' => get_store_id(), 'type' => 1]); $storeMini = StoreMini::find()->where(['appid' => $WechatConfig->app_id, 'is_cancle' => 0])->select('id')->one(); if (empty($storeMini)) { return [ 'code' => 1, 'msg' => "小程序为空" ]; } $form = new WechatThirdForm(); $form->mini_id = $storeMini->id; $result = $form->getMiniQr($storeMini->id, $scene); if ($result['code'] === 0) { //返回图片 return [ 'code' => 0, 'data' => [ 'url' => $result['data'] ] ]; } return $result; } } }