抖音小程序码

admin8个月前Laravel414

public function dyqrcode($uid)
{


   $url = "https://open.douyin.com/api/apps/v1/qrcode/create";
   $data['appid'] = $this->client_key;
   $data['app_name'] = 'douyin';
   $data['is_circle_code'] = true;
   $data['path'] = urlencode('pages/indexs/start/start?spcode=' . $uid);
   $data = json_encode($data);
   $curl = curl_init();
   curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
   curl_setopt($curl, CURLOPT_URL, $url);
   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
   curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
   curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
   $headers = array(
       'access-token: ' . $this->Token(),
       'Content-Type: application/json',
       'Content-Length: ' . strlen($data)
   );
   curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
   if (!empty($data)) {
       curl_setopt($curl, CURLOPT_POST, 1);
       curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
   }
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   $output = curl_exec($curl);
   curl_close($curl);
   $result = json_decode($output, true);
   if ($result['err_no'] == '0') {
       $imageName = "p_" . date("His", time()) . "_" . rand(1111, 9999) . '.jpg';
       $path = "upload/dyqrcode/" . date("Ymd");
       if (!is_dir($path)) { //判断目录是否存在 不存在就创建
           mkdir($path, 0777, true);
           chmod($path, 0777);
       }
       $imageSrc = $path . "/" . $imageName; //图片名字
       $r = file_put_contents($imageSrc, base64_decode($result['data']['img']));//返回的是字节数
       Db::table('member')->where(array('id' => $uid))->update(['dy_qrcode' => $imageSrc]);
       return $path . "/" . $imageName;
   } else {
       return $this->error($result['err_msg']);
   }
}

返回列表

上一篇:验证手机号

下一篇:获取域名

相关文章

微信支付V2

   public static function unifiedorder($openid, $out_trade_no, $total_fee, $notify)...

接口返回处理

public function __construct()    {        $action = request()->rout...

PHP 严格类型

只需在 PHP 代码文件的开头加上declare(strict_types = 1);这一行魔法代码,就能开启严格类型检查之旅。...

获取域名

/** * 获取域名 */public function domain(){    return request()->getSchemeAndHttpHost();}...

设置项目编号

$max = Db::table('member')->max('id') ?? 0; if ($max < 100000) { $cd = $this->create...

编辑用户信息

*/public function useredit(){    $avatar = request()->input('avatar');   &...