qqAuto.tsx 9.1 KB

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