如何使用javascript连接两个encodedUri字符串?
我正在尝试连接两个字符串,但我无法这样做。我可以发送消息,但我只收到短信,没有链接。有人能给我建议解决这个问题的方法吗?以下是我尝试过的解决方案:如何使用javascript连接两个encodedUri字符串?,javascript,string,Javascript,String,我正在尝试连接两个字符串,但我无法这样做。我可以发送消息,但我只收到短信,没有链接。有人能给我建议解决这个问题的方法吗?以下是我尝试过的解决方案: const sms = async (phoneNumber, textMessage, senderId) => { // if (!text || typeof text != "string") { // throw new TypeError("Second argument text is required, it
const sms = async (phoneNumber, textMessage, senderId) => {
// if (!text || typeof text != "string") {
// throw new TypeError("Second argument text is required, it must be string");
// }
try {
const link = "https://google.com/uLK1aeSA98DDrktU7/";
const links = encodeURI(link);
const plainText = encodeURI(textMessage);
const text = plainText.concat(links);
const response = await request({
method: "POST",
uri: `https://www.smsalert.co.in/api/push.json?apikey=${apiKey}&sender=${senderId}&mobileno=${phoneNumber}&text=${text}`,
json: true,
});
// console.log(response);
return response;
} catch (error) {
console.error(error);
}
};
sms("+91xxxxxx", "Have you Checked-in.", "FUNPRA");
我得到的输出
Have%20you%20Checked-in.https://google.com/uLK1aeSA98DDrktU7/
你是说
const text=“您登记入住了吗。”;
常量url=”https://google.com/uLK1aeSA98DDrktU7/"
let link=新URL(URL+文本);
console.log(link.href)
//或
常量uri=encodeURIComponent(url+文本)
console.log(uri)
您想要的是encodeURIComponent
,而不是encodeURI
。您也可以使用+
而不是.concat(…)
,但这并不重要。@sidgate最后一行的短信(“+91xxxxxx”,“您签入了吗?”,“FUNPRA”)中给出了示例textMessage
代码>呼叫。这是否回答了您的问题?请张贴“输出我期待”太多