qqAuto.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { useCallback, useState } from "react"
  2. import React from 'react'
  3. import { Col, Row, Radio, Input, Button, message, Space, Image, Modal, Popconfirm } from "antd";
  4. let name = {
  5. 0: '小说账号失败列表:',
  6. 1: '游戏账号失败列表:',
  7. }
  8. var time: any = null
  9. let api= "http://47.99.157.216:8023"
  10. // let api= "http://127.0.0.1:8023"
  11. function QQAuth(props: { qqVisible: boolean, callBack: () => void }) {
  12. const { qqVisible, callBack } = props
  13. let [visible, setVisible] = useState(false)
  14. let [loading,setLoading]=useState(false)
  15. let [codeUrl, setCodeUrl] = useState('')
  16. let [err, setErr] = useState({})
  17. let [data, setData] = useState({
  18. userId: localStorage.getItem('userId'),
  19. adAppType: 0,
  20. users: [],
  21. callbackPage: 'http%3A%2F%2Ferp.zanxiangnet.com%2FadCode',
  22. authorization: `Bearer ${sessionStorage.getItem('Admin-Token')}`
  23. })
  24. let adAppIdonChange = useCallback((checkedValue) => {
  25. let v = checkedValue.target.value
  26. console.log("checkedValue===>",v)
  27. setData({ ...data, adAppType:v})
  28. }, [data])
  29. let submit = useCallback(() => {
  30. if (data.users.some(user => isNaN(user))) {
  31. message.error('账号请使用数字!!!!!!')
  32. return
  33. }
  34. setLoading(true)
  35. fetch(api+'/qq/auth', {
  36. method: 'POST',
  37. headers: {
  38. "content-type": "application/json",
  39. },
  40. body: JSON.stringify(data)
  41. }).then(res => res.json()).then(r => {
  42. if (r?.data?.codeImgUrl) {
  43. setCodeUrl(r?.data?.codeImgUrl)
  44. setVisible(true)
  45. let n=0
  46. time = setInterval(() => {
  47. if(n< 60){
  48. n+=1
  49. fetch(`${api}/qq/isOk?userId=${localStorage.getItem('userId')}`, {
  50. method: 'GET'
  51. }).then(res => res.json()).then(r => {
  52. if (r.data) {
  53. setVisible(false)
  54. setCodeUrl("")
  55. clearInterval(time)
  56. setLoading(false)
  57. }
  58. })
  59. }else{
  60. message.error('扫码超时请重新扫码!')
  61. setVisible(false)
  62. setCodeUrl("")
  63. clearInterval(time)
  64. setLoading(false)
  65. }
  66. }, 1000)
  67. } else {
  68. message.success('已经开始授权,稍后自行查看结果!')
  69. setLoading(false)
  70. }
  71. console.log(r)
  72. })
  73. }, [data])
  74. let query = () => {
  75. fetch(`${api}/qq/queryErr?userId=${localStorage.getItem('userId')}`, {
  76. method: 'GET'
  77. }).then(res => res.json()).then(r => {
  78. console.log(r)
  79. setErr(r.data)
  80. })
  81. }
  82. let del = () => {
  83. fetch(`${api}/qq/delCookie?userId=${localStorage.getItem('userId')}`, {
  84. method: 'GET'
  85. }).then(res => res.json()).then(r => {
  86. console.log(r)
  87. message.success('清理成功!!!!请重新扫码授权登录!!!')
  88. })
  89. }
  90. let userIdChange = useCallback((e) => {
  91. let value = e.target.value
  92. let arr = value.split(/,|,/)
  93. let newArr = arr?.map((str: string) => Number(str.replace(/\s/ig, '')))
  94. setData({ ...data, users: newArr })
  95. }, [data])
  96. return <Modal
  97. visible={qqVisible}
  98. footer={null}
  99. width={800}
  100. onCancel={callBack}
  101. maskClosable={false}
  102. >
  103. <div>
  104. <Row>
  105. <Col span='24'>
  106. <Row>
  107. <Col span={3}><h3>平台选择:</h3></Col>
  108. <Col span={20}>
  109. <Radio.Group style={{ width: '100%' }} onChange={adAppIdonChange} defaultValue={data.adAppType}>
  110. <Radio value={0}>小说</Radio>
  111. {/* <Radio value={1}>游戏</Radio> */}
  112. </Radio.Group>
  113. </Col>
  114. </Row>
  115. </Col>
  116. <Col span='24'>
  117. <Row>
  118. <Col span={3}><h3>账号ID:</h3></Col>
  119. <Col span={20}> <Input.TextArea placeholder='多个账号请以,号隔开例:123456,222333,444444' rows={5} onChange={userIdChange} allowClear></Input.TextArea></Col>
  120. </Row>
  121. </Col>
  122. </Row>
  123. <Row style={{ display: 'flex', justifyContent: 'center', marginTop: 20 }}>
  124. <Space>
  125. <Button type='primary' onClick={submit} loading={loading}>提交</Button>
  126. <Button type='default' onClick={query} >查询授权失败账号</Button>
  127. <Popconfirm title={'清除账号状态将清除所有失败记录,并清空上一次扫码授权状态!'} onConfirm={del} >
  128. <Button type='primary' danger >清除账号状态</Button>
  129. </Popconfirm>
  130. </Space>
  131. </Row>
  132. <Row>
  133. {
  134. Object.keys(err).map((key, i) => {
  135. return <Col key={i} span={24}>
  136. <div>
  137. <h4>{name[key]}</h4>
  138. <p>{err[key]?.join()}</p>
  139. </div>
  140. </Col>
  141. })
  142. }
  143. </Row>
  144. <Modal
  145. visible={visible}
  146. footer={null}
  147. width={200}
  148. onCancel={() => setVisible(false)}
  149. maskClosable={false}
  150. >
  151. <Image
  152. style={{ width: 150 }}
  153. src={codeUrl} />
  154. </Modal>
  155. </div>
  156. </Modal>
  157. }
  158. export default QQAuth