抖音小程序登录

admin2年前Laravel707

$code = request()->input('code');
$nickname = request()->input('nickName');
$avatar = request()->input('avatarUrl');
$pid = request()->input('pid');
if (!$code) {
   return $this->error('请传入code值');
}
$score = $this->system();
$url = 'https://developer.toutiao.com/api/apps/v2/jscode2session';
$msg['appid'] = $this->client_key;
$msg['secret'] = $this->client_secret;
$msg['code'] = $code;
$res = $this->curl($url, json_encode($msg));
$data = json_decode($res, 1);
if ($data['err_tips'] == 'success' && $data['err_no'] == '0') {
   $openid = $data['data']['openid'];
   $num = Db::table('member')->where(array('dy_openid' => $openid, 'status' => 1))->first();
   if ($num) {
       if ($num->mobile) {
           $tag['is_mobile'] = 1;
       } else {
           $tag['is_mobile'] = 0;
       }
       $token = JWT::encode($num->id, self::$tokenKey);
       $tag['token'] = $token;
       return $this->success('ok', $tag);
   } else {
       $tag['token'] = '';
       $tag['openid'] = $openid;
       return $this->success('登录成功', $tag);

}



protected function curl($url, $data)
{
   $ch = curl_init();
   $params[CURLOPT_URL] = $url;    //请求url地址
   $params[CURLOPT_HEADER] = FALSE; //是否返回响应头信息
   $params[CURLOPT_SSL_VERIFYPEER] = false;
   $params[CURLOPT_SSL_VERIFYHOST] = false;
   $params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
   $params[CURLOPT_POST] = true;
   $params[CURLOPT_POSTFIELDS] = $data;
   curl_setopt_array($ch, $params); //传入curl参数
   $content = curl_exec($ch); //执行
   curl_close($ch); //关闭连接
   return $content;
}

相关文章

发送公众号信息

* 发送消息 */public function tosend($openid, $title, $content, $time, $aid){    $tokens = $thi...

压缩图片

public static function size($id, $img) { try { list($width, $height, $img_type, $attr) = @getimages...

生成唯一的订单号

public function get_order_sn() {     return date('Ymd') ...

小程序的二维码

    public function qrcode()    {        $qcode = "http...

阿里云发送短信

public function sms(){    $moile = request()->input('mobile');    if...

按照距离远近排序

   $distance = "ACOS(SIN(( $lat * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((...