Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript连接两个encodedUri字符串?_Javascript_String - Fatal编程技术网

如何使用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
呼叫。这是否回答了您的问题?请张贴“输出我期待”太多