如何使用 WhatsApp Api 从企业向客户发送消息
How to use WhatsApp Api to send messages from Businesses to Customers
我正在为本地企业开发 B2C 应用程序。我将为企业和客户开发单独的应用程序,但为了迎合还没有该应用程序的客户,我希望为企业提供这样的功能,即他们可以通过我的业务应用程序从客户的 WhatsApp 号码向客户的 WhatsApp 发送发票。
我怎样才能做到这一点?
提前致谢
这取决于你的发票是什么格式,如果是纯文本或图像,对于Android你可以使用Intent
分享它到 WhatsApp
1.分享文字
public void onClick(View view) {
String packageName = "com.tencent.mm"; //you can try "com.whatsapp" for WhatsApp or "com.facebook.orca" for Messenger
if (isAppInstalled(packageName)) { //if app found
String text = "I love you";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, text);
intent.setPackage(packageName);
startActivity(intent);
} else {
Toast.makeText(view.getContext(), "WeChat is not installed", Toast.LENGTH_SHORT).show();
}
}
private boolean isAppInstalled(String packageName) {
boolean installed = true;
try {
getPackageManager().getPackageInfo(packageName, 0); //if package not found, exception will be thrown
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
2。分享图片
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, imageUri); //uri from loading onto the page
intent.setPackage(packageName); //such as "com.tencent.mm"
startActivity(intent);
}
});
我正在为本地企业开发 B2C 应用程序。我将为企业和客户开发单独的应用程序,但为了迎合还没有该应用程序的客户,我希望为企业提供这样的功能,即他们可以通过我的业务应用程序从客户的 WhatsApp 号码向客户的 WhatsApp 发送发票。
我怎样才能做到这一点?
提前致谢
这取决于你的发票是什么格式,如果是纯文本或图像,对于Android你可以使用Intent
分享它到 WhatsApp
1.分享文字
public void onClick(View view) {
String packageName = "com.tencent.mm"; //you can try "com.whatsapp" for WhatsApp or "com.facebook.orca" for Messenger
if (isAppInstalled(packageName)) { //if app found
String text = "I love you";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, text);
intent.setPackage(packageName);
startActivity(intent);
} else {
Toast.makeText(view.getContext(), "WeChat is not installed", Toast.LENGTH_SHORT).show();
}
}
private boolean isAppInstalled(String packageName) {
boolean installed = true;
try {
getPackageManager().getPackageInfo(packageName, 0); //if package not found, exception will be thrown
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
2。分享图片
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, imageUri); //uri from loading onto the page
intent.setPackage(packageName); //such as "com.tencent.mm"
startActivity(intent);
}
});