微信公众号h5登录

admin9个月前Thinkphp400

public function getCode()
{

   $order_id = '95896766';
   $config = config('wechat.official_account');
   $appid = $config['app_id'];
   $redirect_uri = urlencode('https://bianque-h5-test.quansuwangluo.com/api/card/getuserinfo?order_id=' . $order_id);
   $scope = 'snsapi_userinfo'; // 如果需要用户信息,使用snsapi_userinfo
   $state = 'STATE'; // 自定义状态值
   $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=$scope&state=$state#wechat_redirect";
   header("Location:{$url}");
   exit;
}


public function getuserinfo($code, $order_id)
{
   $config = config('wechat.official_account');
   $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $config['app_id']
       . "&secret=" . $config['secret'] . "&code=" . $code . "&grant_type=authorization_code";
   $jsonResult = file_get_contents($url);
   $resultArray = json_decode($jsonResult, true);
   echo '<pre>';
   print_r($resultArray);
   print_r($order_id);
   exit;
   $access_token = $resultArray["access_token"];
}

相关文章

thinkphp 加cache锁

$lockKey = 'user_lock_requirement' . $this->user_id; $isLocked = Cache::get($lockKey); if ($isLo...

关注公众号登录

/* * 服务端生成带唯一标识二维码并将唯一标识返回给前端 */ public function wx_code() { $scene_str...

查找重复的数据

$data = Db::name('about_product_list')->field('id,title,count(id) as num')->gr...

支付宝生成支付二维码

public function alipay($pay_order_no = '20241114123331000000195475', $uid = 1, $url = '') {...

fastadmin上传图片并压缩并加水印

public function image() { // $url = 'uploads/20241026/8f32aebb8be904c5c01ea80de534880...

微信卡卷html 领取的签名

/* * 创建签名 */public function sign(){    $cardId = 'p7YU46qidv5_baigH0Ds4ObP7MDg'; &...