Browse Source

店铺二维码生成修改

master
liangyuyan 5 years ago
parent
commit
9108dedc86
  1. 6
      app/Admin/Common/Images.php
  2. 69
      app/Admin/Common/StoreQrCode.php
  3. 9
      app/Admin/Controllers/v3/StoreController.php
  4. 16
      config/wechat.php

6
app/Admin/Common/Images.php

@ -20,7 +20,7 @@ class Images extends AdminController
$appid= config('wechat.mini_program.default')['app_id']; $appid= config('wechat.mini_program.default')['app_id'];
$secret=config('wechat.mini_program.default')['secret']; $secret=config('wechat.mini_program.default')['secret'];
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;
$url = config('wechat.defaults.token').$appid."&secret=".$secret;
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
@ -43,7 +43,7 @@ class Images extends AdminController
"width"=>100 "width"=>100
); );
$data = json_encode($data); $data = json_encode($data);
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token."";
$url = config('wechat.QR_code.default.mini_code_url').$access_token."";
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
@ -68,7 +68,7 @@ class Images extends AdminController
"width"=>280 "width"=>280
); );
$data = json_encode($data); $data = json_encode($data);
$url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=".$access_token."";
$url = config('wechat.QR_code.default.wx_code_url').$access_token;
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_URL,$url);

69
app/Admin/Common/StoreQrCode.php

@ -35,7 +35,7 @@ class StoreQrCode extends AdminController
public function SetStoreWeChatCode($id) public function SetStoreWeChatCode($id)
{ {
$codeStore = $this->images->createQrCode($id,'zh_cjdianc/pages/takeout/takeoutindex'); $codeStore = $this->images->createQrCode($id,'zh_cjdianc/pages/takeout/takeoutindex');
$storeImgPath = 'QR_code/code_store_img/wx_store_'.$id.'.jpg';
$storeImgPath = 'QR_code/code_store_img/wx_store_'.$id.'_'.md5(time()).'.jpg';
$res = $this->images->uploadOss($codeStore,$storeImgPath); $res = $this->images->uploadOss($codeStore,$storeImgPath);
if($res){ if($res){
return ['status' => true ,'path' => $storeImgPath]; return ['status' => true ,'path' => $storeImgPath];
@ -48,19 +48,13 @@ class StoreQrCode extends AdminController
*/ */
public function SetPayWeChatCode($id) public function SetPayWeChatCode($id)
{ {
// $isCREATE = env('IS_CREATE_WECHAT_MINI_QR_CODE',1);
// if($isCREATE == 0){
if(config('wechat.QR_code.default.is_wx_code') == 1){
$codeStore = $this->images->createWeChatQrCode('?scene='.$id,'zh_cjdianc/pages/seller/fukuan');
$storeImgPath = 'QR_code/code_pay_img/wx_pay_'.$id.'_'.md5(time()).'.jpg';
}else{
$codeStore = $this->images->createQrCode($id,'zh_cjdianc/pages/seller/fukuan'); $codeStore = $this->images->createQrCode($id,'zh_cjdianc/pages/seller/fukuan');
$storeImgPath = 'QR_code/code_minipay_img/wx_minipay_'.$id.'.jpg';
// }else{
// $codeStore = $this->images->createWeChatQrCode('?scene='.$id,'zh_cjdianc/pages/seller/fukuan');
// $storeImgPath = 'QR_code/code_pay_img/wx_pay_'.$id.'.jpg';
// // 裁剪
// }
// 裁剪测试
// $this->imageManager->make()->resize(270,270)->insert($codeStore);
$storeImgPath = 'QR_code/code_minipay_img/wx_minipay_'.$id.'_'.md5(time()).'.jpg';
}
$res = $this->images->uploadOss($codeStore,$storeImgPath); $res = $this->images->uploadOss($codeStore,$storeImgPath);
if($res){ if($res){
@ -70,53 +64,4 @@ class StoreQrCode extends AdminController
} }
} }
/**
* 店铺收银码裁剪
*/
public function setStoreCodeImg($file_path,$storeId){
$save_path = './QR_code/wx_store_pay_cut/wx_pay_'.$storeId.'.jpg';
if(!file_exists($save_path)){
//将图片进行裁剪
if(file_exists($file_path)){
$save_width = 270;
$start_spot_x = 5;
$start_spot_y = 5;
$width = 270;
$height = 270;
$this->tailoringImg($save_path,$file_path,$save_width,$start_spot_x,$start_spot_y,$width,$height,1);
}else{
return '';
}
}
return $save_path;
}
/**
* 裁剪图片
*/
public function tailoringImg($save_path,$file_path,$save_width,$start_spot_x,$start_spot_y,$width,$height,$display=1)
{
if(file_exists($file_path) && is_readable($file_path)){
//从字符串中的图像流新建一图像
$src = imagecreatefromstring(file_get_contents($file_path));
//保存图片的高
$save_height = round($save_width*$height/$width);
//根据要保存的宽和高创建图片
$new_image = imagecreatetruecolor($save_width, $save_height);
//生成最后的图片
imagecopyresampled($new_image, $src, 0, 0, $start_spot_x, $start_spot_y, $save_width, $save_height, $width, $height);
// header('Content-Type: image/jpeg');
imagejpeg($new_image,$save_path);
imagedestroy($src);
imagedestroy($new_image);
}
}
} }

9
app/Admin/Controllers/v3/StoreController.php

@ -41,13 +41,11 @@ class StoreController extends AdminController
// 查询一级分类 // 查询一级分类
// $categoryList = CategoryModel::getArray([['parent_id','=',0]]); // $categoryList = CategoryModel::getArray([['parent_id','=',0]]);
$grid->model()->orderBy('id','desc');
$grid->id->sortable(); $grid->id->sortable();
$grid->logo_url->image('',50); $grid->logo_url->image('',50);
$grid->name; $grid->name;
$grid->market_id->display(function ($marketId) use($marketList){ $grid->market_id->display(function ($marketId) use($marketList){
// $market = MarketModel::getMarketInfo($marketId,'name');
return isset($marketList[$marketId]) ? $marketList[$marketId] : ''; return isset($marketList[$marketId]) ? $marketList[$marketId] : '';
}); });
$grid->mm_user_id->display(function ($mmUserId){ $grid->mm_user_id->display(function ($mmUserId){
@ -84,12 +82,11 @@ class StoreController extends AdminController
$filter->like('name'); $filter->like('name');
$filter->equal('market_id')->select($marketList); $filter->equal('market_id')->select($marketList);
}); });
$grid->model()->orderBy('id','desc');
// 每页10条 // 每页10条
$grid->paginate(10); $grid->paginate(10);
$grid->disableDeleteButton();
// $grid->disableDeleteButton();
}); });
} }
@ -282,7 +279,7 @@ class StoreController extends AdminController
// 生成小程序码 店铺 // 生成小程序码 店铺
$sRes = $qrCode->SetStoreWeChatCode($id); $sRes = $qrCode->SetStoreWeChatCode($id);
// 生产小程序码 收银
// 生成二维码 收银
$pRes = $qrCode->SetPayWeChatCode($id); $pRes = $qrCode->SetPayWeChatCode($id);
// 保存图片 // 保存图片

16
config/wechat.php

@ -35,6 +35,11 @@ return [
'level' => env('WECHAT_LOG_LEVEL', 'debug'), 'level' => env('WECHAT_LOG_LEVEL', 'debug'),
'file' => env('WECHAT_LOG_FILE', storage_path('logs/wechat.log')), 'file' => env('WECHAT_LOG_FILE', storage_path('logs/wechat.log')),
], ],
/**
* 获取token请求地址
*/
'token' => 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=',
], ],
/* /*
@ -129,4 +134,15 @@ return [
// //... // //...
// ], // ],
// ], // ],
/*
* 生成二维码
*/
'QR_code' => [
'default' => [
'mini_code_url' => 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=',/* 小程序码 */
'wx_code_url' => 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=',/* 二维码 */
'is_wx_code' => env('WECHAT_WX_CODE_IS_OPEN', 0),/* 是否开启生成二维码 1开启,0关闭*/
],
],
]; ];
Loading…
Cancel
Save