作者 王晓刚
1 个管道 的构建 通过 耗费 0 秒

服务器配置

@@ -43,7 +43,7 @@ class ShareController extends WeChatBaseController @@ -43,7 +43,7 @@ class ShareController extends WeChatBaseController
43 $savePath = './upload/'.$webPath; 43 $savePath = './upload/'.$webPath;
44 //生成带参二维码 44 //生成带参二维码
45 if(!file_exists($savePath)){ 45 if(!file_exists($savePath)){
46 - $prcode_url = $this->get_code($user_id,$url); 46 + $prcode_url = $this->code_img($user_id,$url);
47 } 47 }
48 //保存头像 48 //保存头像
49 $avatar=$this->getImage($user['avatar'],'avatar_'.$user['id']); 49 $avatar=$this->getImage($user['avatar'],'avatar_'.$user['id']);
@@ -186,6 +186,69 @@ class ShareController extends WeChatBaseController @@ -186,6 +186,69 @@ class ShareController extends WeChatBaseController
186 return false; 186 return false;
187 } 187 }
188 } 188 }
  189 +
  190 + public function code_img($my_user_id,$status){
  191 + //生成带参二维码
  192 + $savePath=ROOT_PATH.'public/upload/qrcode/';
  193 + if (!file_exists($savePath)){
  194 + mkdir($savePath, 0777,true);
  195 + }
  196 + $code_img = $this->code_img1($my_user_id,$status);
  197 + $code = file_get_contents($code_img);
  198 + file_put_contents(ROOT_PATH."public/upload/qrcode/code_img28.png",$code);
  199 + return $savePath.'code_img28.png';
  200 + }
  201 +
  202 + /**
  203 + * 生成带参二维码
  204 + */
  205 + public function code_img1($admin_id,$status)
  206 + {
  207 + $options=config('wechat_config');
  208 + $app = new Application($options);
  209 + $accessToken = $app->access_token; // EasyWeChat\Core\AccessToken 实例
  210 + $token = $accessToken->getToken(false);
  211 + $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $token;
  212 + $param = [
  213 + 'expire_seconds' => '',
  214 + 'action_name' => 'QR_LIMIT_STR_SCENE',
  215 + 'action_info' => ['scene' => ['scene_str' => "$admin_id"."-"."$status"]]
  216 + ];
  217 + $result = $this->api_notice_increment($url, json_encode($param));
  218 + $data = json_decode($result, true);
  219 + $ticket = urlencode($data['ticket']);
  220 + $qr_url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket;
  221 + return $qr_url;
  222 + }
  223 +
  224 + /**
  225 + * 获取二维码提交
  226 + */
  227 + public function api_notice_increment($url, $data)
  228 + {
  229 +// $data=json_encode($data);
  230 + $ch = curl_init();
  231 + $header = array("Accept-Charset: utf-8");
  232 + curl_setopt($ch, CURLOPT_URL, $url);
  233 + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  234 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  235 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  236 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  237 + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  238 + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  239 + curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  240 + curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  241 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  242 + $tmpInfo = curl_exec($ch);
  243 + if (curl_errno($ch)) {
  244 + curl_close($ch);
  245 + return $ch;
  246 + } else {
  247 + curl_close($ch);
  248 + return $tmpInfo;
  249 + }
  250 + }
  251 +
189 /** 252 /**
190 * 下载微信头像保存到本地 253 * 下载微信头像保存到本地
191 * @param $url 254 * @param $url