php版本
//add by grj 20231017 start
/**
* 发送微信消息
*
* @return void
*/
public function sendWechatMessage()
{
$data = [
'touser' => $openid,
'msgtype' => 'text',
'text' => ['content' => '你好,欢迎使用我们的微信公众号服务!']
];
$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$ret = curl_exec($ch);
curl_close($ch);
}
//add by grj 20231017 end
//发送微信公众号消息
String message =" {\"msgtype\":\"text\",\"text\":{\"content\":\"确认衣服定制流程!
+rsList.get(i).getName().toString()+"?orderNo="+orderNo+"\\\">请点击\"},\"touser\":\""+
rsList.get(i).getWechatId().toString()+
"\"}";
String accessTokenUrl = "http://www.menggu100.com/test002.php";
try {
String jsonStr = HttpClientUtils.sendPost(accessTokenUrl);
JSONObject jsonToken = JSONObject.fromObject(jsonStr);
String accessToken = jsonToken.getString("access_token");
System.out.println(accessToken);
String postUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + accessToken;
String res = HttpClientUtils.sendPostJsonStr(postUrl, message);
System.out.println(res);
} catch (IOException e) {
e.printStackTrace();
}