Commit 2fbefe86 by zhangleyuan

feat:接口联调

parent ed5f966d
/* /*
* @Author: 吴文洁 * @Author: 吴文洁
* @Date: 2020-08-31 09:34:31 * @Date: 2020-08-31 09:34:31
* @LastEditors: 吴文洁 * @LastEditors: zhangleyuan
* @LastEditTime: 2020-08-31 09:35:36 * @LastEditTime: 2021-01-05 15:43:31
* @Description: * @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有 * @Copyright: 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -32,27 +32,12 @@ class Axios { ...@@ -32,27 +32,12 @@ class Axios {
params: any, params: any,
options: FetchOptions = { requestType: 'json' } options: FetchOptions = { requestType: 'json' }
): Promise<any> { ): Promise<any> {
const _url = `${url}?p=w&v=v${VERSION}&userType=${USER_TYPE}&token=${User.getToken()}&uid=${User.getUid()}&tid=${User.getTid()}&aid=${User.getAid()}`; const _url = `${url}`;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const { NewVersion, currentUserInstInfo } = window;
const { instId } = currentUserInstInfo;
const instance: AxiosInstance = axios.create({ const instance: AxiosInstance = axios.create({
timeout: TIME_OUT, timeout: TIME_OUT,
responseType: 'json', responseType: 'json',
headers: { headers: {
instId,
p: 'w',
v: 'VERSION',
vn: `v${VERSION}`,
project: PROJECT,
userType: USER_TYPE,
cid: User.getCid(),
uid: User.getUid(),
tid: User.getTid(),
token: User.getToken(),
bizAccountId: User.getAid(),
xmVersion: NewVersion ? '5.0' : '4.0',
'Content-Type': options.requestType === 'json' ? 'application/json; charset=UTF-8' : 'application/x-www-form-urlencoded', 'Content-Type': options.requestType === 'json' ? 'application/json; charset=UTF-8' : 'application/x-www-form-urlencoded',
} }
}); });
......
/* /*
* @Author: 吴文洁 * @Author: 吴文洁
* @Date: 2020-08-31 09:34:51 * @Date: 2020-08-31 09:34:51
* @LastEditors: 吴文洁 * @LastEditors: zhangleyuan
* @LastEditTime: 2020-08-31 09:35:25 * @LastEditTime: 2021-01-05 15:33:19
* @Description: * @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有 * @Copyright: 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -22,10 +22,13 @@ class Service { ...@@ -22,10 +22,13 @@ class Service {
static Sales(url: string, params: any, option: any) { static Sales(url: string, params: any, option: any) {
return Axios.post('POST', `sales/${url}`, params, option); return Axios.post('POST', `sales/${url}`, params, option);
} }
static hades(url: string, params: any, option: any) {
return Axios.post('POST', `hades/${url}`, params, option);
}
static post(url: string, params: any, option: any) { static post(url: string, params: any, option: any) {
return Axios.post('POST', url, params, option); return Axios.post('POST', url, params, option);
} }
} }
export default Service; export default Service;
\ No newline at end of file
...@@ -8,30 +8,73 @@ class Authorize extends React.Component { ...@@ -8,30 +8,73 @@ class Authorize extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
code:'',
ticket:'',
hasBindWechat:false
} }
} }
componentDidMount() { componentDidMount() {
const searchParams = this.props.location.search const searchParams = this.props.location.search;
console.log('参数',queryString.parse(searchParams)); const {code,ticket} = queryString.parse(searchParams);
this.setState({
code,
ticket
})
if(!code){
this.setState({
ticketState:"SCAN_SUCCESS"
},()=>this.changeCodeState())
}else{
this.getWechatUserInfo();
}
}
changeCodeState = ()=>{
let {ticket,ticketState} = this.state;
const params = {
ticket,
ticketState
} }
wechatLogin = () => { Service.hades('/anon/hades/changeTicketState',params).then(
)
}
wechatAuthorize = () => {
let path = window.location.origin + window.location.pathname; let path = window.location.origin + window.location.pathname;
let htmlUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + AppId + let htmlUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + AppId +
'&redirect_uri=' + encodeURIComponent(path) + '&redirect_uri=' + encodeURIComponent(path) +
'&response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect'; '&response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect';
window.location.href = htmlUrl; window.location.href = htmlUrl;
} }
getWechatUserInfo = ()=>{
let {ticket,code} = this.state;
const params = {
appTermEnum: "XIAOMAI_CLOUD_CLASS_PC_WEB_ADMIN",
code,
storeId:"1192022572770412395",
ticket
}
Service.hades('/anon/hades/bindWeChat',params).then(
this.setState({
hasBindWechat:true
})
)
}
render() { render() {
const { hasBindWechat } = this.state
return ( return (
<div className="authorize-page"> <div className="authorize-page">
<div> <div>
<img src="https://image.xiaomaiketang.com/xm/HsCjyKTbWw.png" className="avatar-img"></img> <img src="https://image.xiaomaiketang.com/xm/HsCjyKTbWw.png" className="avatar-img"></img>
</div> </div>
<div> <div>
<button className="login-btn" onClick={this.wechatLogin}>微信登录</button> { !hasBindWechat &&
<button className="login-btn" onClick={this.wechatAuthorize}>微信登录</button>
}
{ hasBindWechat &&
<button className="login-btn" onClick={this.wechatAuthorize}>已登录</button>
}
</div> </div>
</div> </div>
) )
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment