qqAuto.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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, adAppType: 0 | 1, title: string, smType?: "QQ" | "WX", isOld?: boolean }) {
  12. const { qqVisible, callBack, adAppType, smType, title, isOld } = 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 [outTime,setOutTime]=useState(0)
  18. let [data, setData] = useState({
  19. userId: localStorage.getItem('userId'),
  20. adAppType,
  21. users: [],
  22. callbackPage: 'http%3A%2F%2Ferp.zanxiangnet.com%2FadCode',
  23. authorization: `Bearer ${sessionStorage.getItem('Admin-Token')}`,
  24. smType: smType ? "WX" : "QQ",
  25. isOld
  26. })
  27. let adAppIdonChange = useCallback((checkedValue) => {
  28. let v = checkedValue.target.value
  29. console.log("checkedValue===>", v)
  30. setData({ ...data, adAppType: v })
  31. }, [data])
  32. let submit = useCallback(() => {
  33. if (data.users.some(user => isNaN(user))) {
  34. message.error('账号请使用数字!!!!!!')
  35. return
  36. }
  37. console.log(data)
  38. setLoading(true)
  39. fetch(api + '/qq/auth', {
  40. method: 'POST',
  41. headers: {
  42. "content-type": "application/json",
  43. },
  44. body: JSON.stringify(data)
  45. }).then(res => res.json()).then(r => {
  46. if (r?.data?.codeImgUrl) {
  47. setCodeUrl(r?.data?.codeImgUrl)
  48. setVisible(true)
  49. let n = 0
  50. let overTime = data.smType === 'QQ' ? 60 : 240
  51. time = setInterval(() => {
  52. if ( n < overTime) {
  53. n += 1
  54. fetch(`${api}/qq/isOk?userId=${localStorage.getItem('userId')}&smType=${data.smType}`, {
  55. method: 'GET'
  56. }).then(res => res.json()).then(r => {
  57. if (r.data) {
  58. setVisible(false)
  59. setCodeUrl("")
  60. clearInterval(time)
  61. setLoading(false)
  62. }
  63. })
  64. } else {
  65. message.error('扫码超时请重新扫码!')
  66. setVisible(false)
  67. setCodeUrl("")
  68. clearInterval(time)
  69. setLoading(false)
  70. }
  71. setOutTime(overTime-n)
  72. }, 1000)
  73. } else {
  74. message.success('已经开始授权,稍后自行查看结果!如遇到问题请点击清除账号状态按钮重试!')
  75. setLoading(false)
  76. }
  77. console.log(r)
  78. })
  79. }, [data])
  80. let query = () => {
  81. fetch(`${api}/qq/queryErr?userId=${localStorage.getItem('userId')}`, {
  82. method: 'GET'
  83. }).then(res => res.json()).then(r => {
  84. console.log(r)
  85. setErr(r.data)
  86. })
  87. }
  88. let del = () => {
  89. fetch(`${api}/qq/delCookie?userId=${localStorage.getItem('userId')}`, {
  90. method: 'GET'
  91. }).then(res => res.json()).then(r => {
  92. console.log(r)
  93. message.success('清理成功!!!!请重新扫码授权登录!!!')
  94. })
  95. }
  96. let userIdChange = useCallback((e) => {
  97. let value = e.target.value
  98. let arr = value.split(/,|,/)
  99. let newArr = arr?.map((str: string) => Number(str.replace(/\s/ig, '')))
  100. setData({ ...data, users: newArr })
  101. }, [data])
  102. return <Modal
  103. open={qqVisible}
  104. footer={null}
  105. width={800}
  106. onCancel={callBack}
  107. maskClosable={false}
  108. title={<>{title}<span style={{ color: 'red' }}>(如需更换手机扫码请先点击清除账号状态)</span></>}
  109. >
  110. <div>
  111. <Row>
  112. <Col span='24'>
  113. <Row>
  114. <Col span={3}><h3>扫码渠道:</h3></Col>
  115. <Col span={20}>
  116. <Radio.Group style={{ width: '100%' }} onChange={(e) => {
  117. setData({ ...data, smType: e.target.value })
  118. }} defaultValue={data.smType}>
  119. <Radio value={"QQ"}>QQ</Radio>
  120. {!isOld && <Radio value={"WX"}>微信</Radio>}
  121. </Radio.Group>
  122. </Col>
  123. </Row>
  124. </Col>
  125. <Col span='24'>
  126. <Row>
  127. <Col span={3}><h3>平台选择:</h3></Col>
  128. <Col span={20}>
  129. <Radio.Group style={{ width: '100%' }} onChange={adAppIdonChange} defaultValue={data.adAppType}>
  130. {adAppType === 0 ? <Radio value={0}>小说</Radio> : <Radio value={1}>游戏</Radio>}
  131. </Radio.Group>
  132. </Col>
  133. </Row>
  134. </Col>
  135. <Col span='24'>
  136. <Row>
  137. <Col span={3}><h3>账号ID:</h3></Col>
  138. <Col span={20}> <Input.TextArea placeholder='多个账号请以,号隔开例:123456,222333,444444' rows={5} onChange={userIdChange} allowClear></Input.TextArea></Col>
  139. </Row>
  140. </Col>
  141. </Row>
  142. <Row style={{ display: 'flex', justifyContent: 'center', marginTop: 20 }}>
  143. <Space>
  144. <Button type='primary' onClick={submit} loading={loading} disabled={data.users.length === 0}>提交</Button>
  145. <Button type='default' onClick={query} >查询授权失败账号</Button>
  146. <Popconfirm title={'清除账号状态将清除所有失败记录,并清空上一次扫码授权状态!'} onConfirm={del} >
  147. <Button type='primary' danger >清除账号状态</Button>
  148. </Popconfirm>
  149. </Space>
  150. </Row>
  151. <Row>
  152. {
  153. Object.keys(err).map((key, i) => {
  154. return <Col key={i} span={24}>
  155. <div>
  156. <h4>{name[key]}</h4>
  157. <p>{err[key]?.join()}</p>
  158. </div>
  159. </Col>
  160. })
  161. }
  162. </Row>
  163. <Modal
  164. open={visible}
  165. footer={null}
  166. width={250}
  167. onCancel={() => { setVisible(false); location.reload() }}
  168. maskClosable={false}
  169. title={<>{data?.smType === 'QQ' ? "QQ扫码" : "微信扫码"}</>}
  170. >
  171. <div style={{ display: 'flex', justifyItems: "center", alignItems: 'center',flexFlow:'column' }}>
  172. <Image
  173. style={{ width: 150 }}
  174. src={codeUrl} />
  175. <strong style={{ color: 'red', width: '100%', textAlign: 'center' }}>扫码成功后或超时自动关闭窗口</strong>
  176. <strong style={{ color: 'red', width: '100%', textAlign: 'center' }}>{outTime > 0 ? outTime : ""}</strong>
  177. </div>
  178. </Modal>
  179. </div>
  180. </Modal>
  181. }
  182. export default QQAuth