feat: WA 二维码更新请求方式;WA 可以保存;修改 WA 消息格式;

dev/supplier-email-drawer
LiaoYijun 9 months ago
parent db041577dc
commit d06eee3c1c

@ -176,11 +176,11 @@ const useAuthStore = create(devtools((set, get) => ({
) )
}, },
setWhatsAppBusiness: async (userId, whatsAppBusiness) => { setWhatsAppProfile: async (userId, whatsAppBusiness, whatsAppNo) => {
const { loginUser, saveUserSession } = get() const { loginUser, saveUserSession } = get()
const postWABAUrl = `${API_HOST}/v2/set_whatsapp_info` const postWABAUrl = `${API_HOST}/v2/set_whatsapp_info`
const params = {opi_sn: userId, whatsapp_waba: whatsAppBusiness}; const params = {opi_sn: userId, whatsapp_waba: whatsAppBusiness, whatsapp_wa: whatsAppNo};
return fetchJSON(postWABAUrl, params) return fetchJSON(postWABAUrl, params)
.then(json => { .then(json => {
@ -188,6 +188,7 @@ const useAuthStore = create(devtools((set, get) => ({
set(() => ({ set(() => ({
loginUser: { loginUser: {
...loginUser, ...loginUser,
whatsAppNo: whatsAppNo,
whatsAppBusiness: whatsAppBusiness, whatsAppBusiness: whatsAppBusiness,
} }
})) }))

@ -10,11 +10,12 @@ function Profile() {
const { notification } = App.useApp() const { notification } = App.useApp()
const [wabaForm] = Form.useForm() const [wabaForm] = Form.useForm()
const [loginUser, setWhatsAppBusiness, isPermitted] = useAuthStore((state) => [ const [loginUser, setWhatsAppProfile, isPermitted] = useAuthStore((state) => [
state.loginUser, state.setWhatsAppBusiness, state.isPermitted state.loginUser, state.setWhatsAppProfile, state.isPermitted
]) ])
const [qrCode, setQRCode] = useState('') const [qrCode, setQRCode] = useState('expired')
const [qrStatus, setQRStatus] = useState('expired')
useEffect(() => { useEffect(() => {
// //
@ -23,11 +24,12 @@ function Profile() {
}, []) }, [])
const handelUpdateWABA = useCallback(() => { const handelUpdateWABA = useCallback(() => {
setWhatsAppBusiness(loginUser.userId, wabaForm.getFieldsValue().whatsAppBusiness) const formValues = wabaForm.getFieldsValue()
setWhatsAppProfile(loginUser.userId, formValues.whatsAppBusiness, formValues.whatsAppNo)
.then(() => { .then(() => {
notification.info({ notification.info({
message: 'Notification', message: 'Notification',
description: '商业号身份设置成功', description: 'WhatsApp 配置成功',
placement: 'top', placement: 'top',
}) })
}) })
@ -48,8 +50,8 @@ function Profile() {
'http://localhost:3031/api/v1/whatsapp/channels/qrcode', 'http://localhost:3031/api/v1/whatsapp/channels/qrcode',
{ phone }) { phone })
.then(r => { .then(r => {
console.info(r)
setQRCode(r.result.qr) setQRCode(r.result.qr)
setQRStatus('active')
}) })
.catch(ex => { .catch(ex => {
console.error(ex) console.error(ex)
@ -57,6 +59,7 @@ function Profile() {
}, []) }, [])
const customStatusRender = (info) => { const customStatusRender = (info) => {
console.info(info)
switch (info.status) { switch (info.status) {
case 'expired': case 'expired':
return ( return (
@ -65,22 +68,14 @@ function Profile() {
style={{ style={{
color: '#52c41a', color: '#52c41a',
}} }}
/>{' '} />
8618754124786 已登录
<p> <p>
<Button type='link' onClick={info.onRefresh}> <Button type='link' onClick={handelGernaterQR}>
<ReloadOutlined /> {info.locale?.refresh} <ReloadOutlined /> {info.locale?.refresh}
</Button> </Button>
</p> </p>
</div> </div>
) )
case 'loading':
return (
<Space direction='vertical'>
<Spin />
<p>Loading...</p>
</Space>
)
case 'scanned': case 'scanned':
return ( return (
<div> <div>
@ -88,7 +83,7 @@ function Profile() {
style={{ style={{
color: 'green', color: 'green',
}} }}
/>{' '} />{' ' + loginUser.whatsAppNo}
{info.locale?.scanned} {info.locale?.scanned}
</div> </div>
) )
@ -200,7 +195,7 @@ function Profile() {
<Typography.Title level={2}>在系统上使用 WhatsApp</Typography.Title> <Typography.Title level={2}>在系统上使用 WhatsApp</Typography.Title>
<Typography.Paragraph> <Typography.Paragraph>
<ul> <ul>
<li>点击生成二维码</li> <li>点击刷新二维码</li>
<li>在手机上打开 WhatsApp</li> <li>在手机上打开 WhatsApp</li>
<li>点击已关联的设备再点击关联新设备</li> <li>点击已关联的设备再点击关联新设备</li>
<li>将手机对准屏幕扫描二维码</li> <li>将手机对准屏幕扫描二维码</li>
@ -210,12 +205,10 @@ function Profile() {
</Col> </Col>
<Col span={6}> <Col span={6}>
<Flex gap='middle' vertical justify={'center'} align={'center'}> <Flex gap='middle' vertical justify={'center'} align={'center'}>
<QRCode size={264} value={qrCode} errorLevel='L' />
<Conditional <Conditional
condition={isPermitted(PERM_USE_WHATSAPP)} condition={isPermitted(PERM_USE_WHATSAPP)}
whenTrue={<Button type='primary' onClick={handelGernaterQR}>生成</Button>} whenTrue={<QRCode size={264} value={qrCode} errorLevel='L' status={qrStatus} statusRender={customStatusRender} />}
/> />
</Flex> </Flex>
</Col> </Col>
</Row> </Row>

@ -213,7 +213,7 @@ const createWhatsApp = async phone => {
text: { text: {
body: text, body: text,
}, },
participant: { customerProfile: {
id: parsePhoneNumber(msg.key.participant), id: parsePhoneNumber(msg.key.participant),
name: msg.pushName, name: msg.pushName,
}, },
@ -229,7 +229,7 @@ const createWhatsApp = async phone => {
text: { text: {
body: text, body: text,
}, },
participant: { customerProfile: {
id: parsePhoneNumber(msg.key.participant), id: parsePhoneNumber(msg.key.participant),
name: msg.pushName, name: msg.pushName,
}, },
@ -250,7 +250,7 @@ const createWhatsApp = async phone => {
status: formatStatus(msg.update.status), status: formatStatus(msg.update.status),
from: msg.key.fromMe ? whatsAppNo : parsePhoneNumber(msg.key.remoteJid), from: msg.key.fromMe ? whatsAppNo : parsePhoneNumber(msg.key.remoteJid),
to: msg.key.fromMe ? parsePhoneNumber(msg.key.remoteJid) : whatsAppNo, to: msg.key.fromMe ? parsePhoneNumber(msg.key.remoteJid) : whatsAppNo,
participant: { customerProfile: {
id: parsePhoneNumber(msg.key.participant), id: parsePhoneNumber(msg.key.participant),
name: msg.pushName, name: msg.pushName,
}, },

Loading…
Cancel
Save