u
This commit is contained in:
		
							parent
							
								
									dbd0e0b13f
								
							
						
					
					
						commit
						b4408ce9f9
					
				
							
								
								
									
										37
									
								
								messenger.js
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								messenger.js
									
									
									
									
									
								
							| @ -35,15 +35,16 @@ module.exports = { | |||||||
|         } |         } | ||||||
|         */ |         */ | ||||||
|         if (result.messageId && result.response === '250 Ok') { |         if (result.messageId && result.response === '250 Ok') { | ||||||
|           console.log({ _at: new Date().toJSON(), _state: 'MSG_SENT_SUCCESS', ...result }, '\n,') |           //console.log({ _at: new Date().toJSON(), _state: 'MSG_SENT_SUCCESS', subject: messageObject.subject, ...result.envelope }, '\n,')
 | ||||||
|           return { _state: 'MSG_SENT_SUCCESS' } |           return { _state: 'MSG_SENT_SUCCESS' } | ||||||
|         } |         } else { | ||||||
|         console.log({ _at: new Date().toJSON(), _state: 'MSG_SEND_FAIL', ...result }, '\n,') |           console.log({ _at: new Date().toJSON(), _state: 'MSG_SEND_FAIL', subject: messageObject.subject, ...result }, '\n,') | ||||||
|           return { _state: 'MSG_SEND_FAIL' } |           return { _state: 'MSG_SEND_FAIL' } | ||||||
|  |         } | ||||||
|       }) |       }) | ||||||
|       .catch((error) => { |       .catch((error) => { | ||||||
|         console.error({ _at: new Date().toJSON(), _state: 'SMS_SEND_ERROR', error }, '\n,') |         console.error({ _at: new Date().toJSON(), _state: 'MSG_SEND_ERROR', subject: messageObject.subject, error }, '\n,') | ||||||
|         return { _state: 'SMS_SEND_ERROR' } |         return { _state: 'MSG_SEND_ERROR' } | ||||||
|       }) |       }) | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
| @ -59,8 +60,8 @@ module.exports = { | |||||||
|   } = {}) { |   } = {}) { | ||||||
|     if (/^\+\d+-\d+$/.test(phone)) { |     if (/^\+\d+-\d+$/.test(phone)) { | ||||||
|       if (!config?.vendor) { |       if (!config?.vendor) { | ||||||
|         console.error({ _at: new Date().toJSON(), _state: 'SMS_CONFIG_MALFORMED' }, '\n,') |         console.error({ _at: new Date().toJSON(), _state: 'SMS_CONFIG_MALFORMED', config }, '\n,') | ||||||
|         return { _state: 'SMS_CONFIG_MALFORMED' } |         return { _state: 'SMS_CONFIG_MALFORMED', phone, config } | ||||||
|       } else if (config.vendor === 'DXTON') { |       } else if (config.vendor === 'DXTON') { | ||||||
|         return await this.sendSmsDxton({ phone, config, msg }) |         return await this.sendSmsDxton({ phone, config, msg }) | ||||||
|       } else if (config.vendor === 'ALIYUN') { |       } else if (config.vendor === 'ALIYUN') { | ||||||
| @ -111,7 +112,7 @@ module.exports = { | |||||||
|           }) |           }) | ||||||
|         }) |         }) | ||||||
|         .on('error', (error) => { |         .on('error', (error) => { | ||||||
|           reject({ _state: 'SMS_SEND_ERROR', error }) |           reject({ _state: 'MSG_SEND_ERROR', error }) | ||||||
|         }) |         }) | ||||||
|     }) |     }) | ||||||
|   }, |   }, | ||||||
| @ -135,11 +136,13 @@ module.exports = { | |||||||
|           if (Code === 'OK') { |           if (Code === 'OK') { | ||||||
|             return { _state: 'MSG_SENT_SUCCESS' } |             return { _state: 'MSG_SENT_SUCCESS' } | ||||||
|           } else { |           } else { | ||||||
|  |             console.error({ _at: new Date().toJSON(), _state: 'MSG_SEND_FAIL', error: result }, '\n,') | ||||||
|             return { _state: 'MSG_SEND_FAIL', error: result } |             return { _state: 'MSG_SEND_FAIL', error: result } | ||||||
|           } |           } | ||||||
|         }, |         }, | ||||||
|         function (error) { |         function (error) { | ||||||
|           return { _state: 'SMS_SEND_ERROR', error } |           console.error({ _at: new Date().toJSON(), _state: 'MSG_SEND_ERROR', error }, '\n,') | ||||||
|  |           return { _state: 'MSG_SEND_ERROR', error } | ||||||
|         } |         } | ||||||
|       ) |       ) | ||||||
|   }, |   }, | ||||||
| @ -162,11 +165,13 @@ module.exports = { | |||||||
|           if (Code === 'Ok') { |           if (Code === 'Ok') { | ||||||
|             return { _state: 'MSG_SENT_SUCCESS' } |             return { _state: 'MSG_SENT_SUCCESS' } | ||||||
|           } else { |           } else { | ||||||
|  |             console.error({ _at: new Date().toJSON(), _state: 'MSG_SEND_FAIL', error: { SendStatusSet, RequestId } }, '\n,') | ||||||
|             return { _state: 'MSG_SEND_FAIL', error: { SendStatusSet, RequestId } } |             return { _state: 'MSG_SEND_FAIL', error: { SendStatusSet, RequestId } } | ||||||
|           } |           } | ||||||
|         }, |         }, | ||||||
|         function (error) { |         function (error) { | ||||||
|           return { _state: 'SMS_SEND_ERROR', error } |           console.error({ _at: new Date().toJSON(), _state: 'MSG_SEND_ERROR', error }, '\n,') | ||||||
|  |           return { _state: 'MSG_SEND_ERROR', error } | ||||||
|         } |         } | ||||||
|       ) |       ) | ||||||
|   }, |   }, | ||||||
| @ -182,14 +187,20 @@ module.exports = { | |||||||
|         data: msgParam, // 模版中的变量的值,例如 { passcode: '234345', purpose: '注册' }
 |         data: msgParam, // 模版中的变量的值,例如 { passcode: '234345', purpose: '注册' }
 | ||||||
|       }) |       }) | ||||||
| 
 | 
 | ||||||
|       return { _state: 'MSG_SENT_SUCCESS', result } // 调用成功,请注意这时不代表发送成功。// { code:0, errCode:0, success:true } 错误码参见 https://uniapp.dcloud.net.cn/uniCloud/send-sms.html
 |       if (result?.errorCode === 0) { | ||||||
|  |         return { _state: 'MSG_SENT_SUCCESS', result } // { code:0, errCode:0, success:true }
 | ||||||
|  |       } else { | ||||||
|  |         // 错误码参见 https://doc.dcloud.net.cn/uniCloud/sms/dev.html
 | ||||||
|  |         console.error({ _at: new Date().toJSON(), _state: 'MSG_SEND_FAIL', error: result }, '\n,') | ||||||
|  |         return { _state: 'MSG_SEND_FAIL', result } | ||||||
|  |       } | ||||||
|     } catch (error) { |     } catch (error) { | ||||||
|       // 调用失败 例如 {"code":undefined,"msg":"短信发送失败:账户余额不足"}
 |       // 调用失败 例如 {"code":undefined,"msg":"短信发送失败:账户余额不足"}
 | ||||||
|  |       console.error({ _at: new Date().toJSON(), _state: 'MSG_SEND_ERROR', error }, '\n,') | ||||||
|       return { |       return { | ||||||
|         _state: 'MSG_SEND_FAIL', |         _state: 'MSG_SEND_ERROR', | ||||||
|         error, // { errCode, errMsg }
 |         error, // { errCode, errMsg }
 | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user