作者 郭盛
1 个管道 的构建 通过 耗费 6 秒

项目授权码

@@ -228,7 +228,7 @@ class Common extends Api @@ -228,7 +228,7 @@ class Common extends Api
228 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 228 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
229 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 229 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
230 curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求 230 curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
231 - curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); // Post提交的数据包 231 + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
232 curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环 232 curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
233 curl_setopt($curl, CURLOPT_HEADER, false); // 开启header 233 curl_setopt($curl, CURLOPT_HEADER, false); // 开启header
234 //curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);//请求头部 234 //curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);//请求头部
@@ -238,4 +238,20 @@ class Common extends Api @@ -238,4 +238,20 @@ class Common extends Api
238 return $result; 238 return $result;
239 } 239 }
240 240
  241 +
  242 + public function shou($farm_id,$project_id,$page){
  243 + //获取二维码链接
  244 + $get_code_url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$this->get_access_token();
  245 + $data = [
  246 + 'scene' => 'farm_id='.$farm_id.'&project_id='.$project_id,
  247 + 'width' => 280,
  248 +// 'page' => $page,
  249 + ];
  250 + $data = json_encode($data);
  251 + $code_res = $this->http_post($get_code_url,$data);
  252 + file_put_contents('upload/project'.$project_id.'.jpg',$code_res);
  253 + $code_url = 'http://trace.w.brotop.cn/upload/project'.$project_id.'.jpg';
  254 + return $code_url;
  255 + }
  256 +
241 } 257 }
@@ -206,11 +206,17 @@ class Project extends Api @@ -206,11 +206,17 @@ class Project extends Api
206 $param['image'] = str_replace($http,'',$param['image']); 206 $param['image'] = str_replace($http,'',$param['image']);
207 $param['createtime'] = time(); 207 $param['createtime'] = time();
208 $data = Db::name('project')->insertGetId($param); 208 $data = Db::name('project')->insertGetId($param);
  209 + //项目二维码
209 $common = new Common(); 210 $common = new Common();
210 $url = 'pages/ShopDetail/ShopDetail?id='.$data; 211 $url = 'pages/ShopDetail/ShopDetail?id='.$data;
211 $thumbnail = $common->imgcode($data,$url); 212 $thumbnail = $common->imgcode($data,$url);
212 - Db::name('project')->where('id',$data)->update(['thumbnail'=>$thumbnail]);  
213 213
  214 + //授权二维码
  215 + $farm_id = $param['farm_id'];
  216 + $project_id = $data;
  217 + $page = 'pages/UserAdmin/UserAdmin';
  218 + $pic = $common->shou($farm_id,$project_id,$page);
  219 + Db::name('project')->where('id',$data)->update(['thumbnail'=>$thumbnail,'pic'=>$pic]);
214 //修改农场项目数 220 //修改农场项目数
215 $project_num = Db::name('farm')->where('id',$param['farm_id'])->field('id,project_num')->find(); 221 $project_num = Db::name('farm')->where('id',$param['farm_id'])->field('id,project_num')->find();
216 $project_num = $project_num['project_num'] + 1; 222 $project_num = $project_num['project_num'] + 1;
@@ -1228,4 +1234,30 @@ class Project extends Api @@ -1228,4 +1234,30 @@ class Project extends Api
1228 } 1234 }
1229 1235
1230 1236
  1237 + /**
  1238 + * @ApiTitle (项目授权码)
  1239 + * @ApiSummary (项目授权码)
  1240 + * @ApiMethod (POST)
  1241 + * @ApiRoute (/api/project/shou)
  1242 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  1243 + *
  1244 + * @ApiParams (name="id", type="int", required=false, description="项目id")
  1245 + *
  1246 + * @ApiReturn({
  1247 + "code": 1,
  1248 + "msg": "SUCCESS",
  1249 + "time": "1553839125",
  1250 + "data": {
  1251 + "id"://项目id
  1252 + "pic"://项目授权码
  1253 + }
  1254 + })
  1255 + */
  1256 + public function shou()
  1257 + {
  1258 + $id = $this->request->param('id');
  1259 + $data = Db::name('project')->where('id',$id)->field('id,pic')->find();
  1260 + $this->success('success',$data);
  1261 + }
  1262 +
1231 } 1263 }
此 diff 太大无法显示。