thinkphp3.2怎么获取微信的openid和头像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了thinkphp3.2怎么获取微信的openid和头像相关的知识,希望对你有一定的参考价值。
参考技术A 得先去微信开放平台申请,要不然没有获取权限 参考技术B 需要有公众号,菜和以获取这些。在php中调用微信提供的开发接口,可以获取用户信息。
微信第三方网页授权获取openid并注册(非小程序)
参考技术A //参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#1<template>
<div>
<div id="login_container"></div>
<div class="formbox">
<el-form
v-if="register"
:model="ruleForm"
status-icon
:rules="rules"
ref="ruleForm"
label-width="80px"
class="demo-ruleForm"
>
<el-form-item label="用户姓名" prop="username">
<el-input v-model="ruleForm.username" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="电话号码" prop="tel">
<el-input v-model="ruleForm.tel" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label-width="0px">
<el-button type="primary" @click="submitForm('ruleForm')"
>注册</el-button
>
</el-form-item>
</el-form>
<el-result v-if="resSuccess" icon="success" title="注册成功"></el-result>
<el-result v-if="isRegister" icon="success" title="已注册"></el-result>
</div>
</div>
</template>
<script>
const appid = "wxb34e237212fbedf7";
const secret = "1c71e022914c722993350ab39bbcbcd0";
import axios from "axios";
const Base64 = require("js-base64").Base64;
export default
data()
let checkTel = (rule, value, callback) =>
if (!value)
return callback(new Error("电话号码不能为空"));
setTimeout(() =>
callback();
, 1000);
;
let validateName = (rule, value, callback) =>
if (value === "")
callback(new Error("姓名不能为空"));
else
callback();
;
return
code: "",
openid: "", //o2bOZ1TcyQMXYKe4PQZuAFnnjjDM
register: false,
resSuccess: false,
isRegister: false,
res: "init",
ruleForm:
username: "",
tel: "",
,
rules:
username: [ validator: validateName, trigger: "blur" ],
tel: [ validator: checkTel, trigger: "blur" ],
,
;
,
mounted()
// if (!window.localStorage.getItem("openId"))
// 如果缓存localStorage中没有微信openId,则授权
this.getCode();
// this.getVerify()
//
,
methods:
getCode()
// 非静默授权,第一次有弹框
,
;
</script>
<style>
.formbox
width: 90%;
margin: 100px auto;
</style>
以上是关于thinkphp3.2怎么获取微信的openid和头像的主要内容,如果未能解决你的问题,请参考以下文章
微信小程序用户的openId如何与企业微信的userId关联