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 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)
.then(json => {
@ -188,6 +188,7 @@ const useAuthStore = create(devtools((set, get) => ({
set(() => ({
loginUser: {
...loginUser,
whatsAppNo: whatsAppNo,
whatsAppBusiness: whatsAppBusiness,
}
}))

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

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

Loading…
Cancel
Save