如何直接从我的Flutter网络应用程序向WhatsApp Business发送消息?

dbf7pr2w  于 2023-01-27  发布在  Flutter
关注(0)|答案(1)|浏览(149)

我正在构建一个flutter网络应用程序,它必须能够在特定的WhatsApp业务号码和WhatsApp号码上发送消息。我到底应该怎么做?如果用户的设备有WhatsApp或WhatsApp业务,他就会打开它。但我的问题是,如果用户的设备同时有WhatsApp和WhatsApp业务,我希望在一个条件下打开一个。

var whatsappURlAndroid = "https://wa.me/$whatsappNumber/?text=Hi";
var whatappURLIos ="https://wa.me/$whatsappNumber?text=${Uri.parse("hello")}";
var webWhatsapp= "https://web.whatsapp.com/send?phone=$whatsappNumber&text=Hello";

if (defaultTargetPlatform == TargetPlatform.iOS) {
  await launch(whatappURLIos, forceSafariVC: false);
}else if(defaultTargetPlatform == TargetPlatform.android){
  await launch(whatsappURlAndroid);
}
else{
  await launch(webWhatsapp);
}
r3i60tvu

r3i60tvu1#

FocusManager.instance.primaryFocus?.unfocus();

var whatsappUrl =
      "whatsapp://send?phone=${_countryCodeController.text + _phoneController.text}" +
          "&text=${Uri.encodeComponent(_messageController.text)}";
  try {
    launch(whatsappUrl);
  } catch (e) {
    //To handle error and display error message
    Helper.errorSnackBar(
        context: context, message: "Unable to open whatsapp");
  }
},

相关问题