Browse Source

test message

master
dutsc 3 years ago
parent
commit
aae922eb8e
  1. 95
      mobile/source/helpers/dalianpay/demo/wxnotify.php

95
mobile/source/helpers/dalianpay/demo/wxnotify.php

@ -31,52 +31,53 @@
session_start(); session_start();
$logFilePath = './wxlogde_decrypt.txt'; // 日志文件保存路径 $logFilePath = './wxlogde_decrypt.txt'; // 日志文件保存路径
file_put_contents($logFilePath, "message:\n\r", LOCK_EX); file_put_contents($logFilePath, "message:\n\r", LOCK_EX);
$openid = $_SESSION['openid'];
$template_id = '5JCt5gNGM7sfwWnRqwWsjH138DixCFJ7sPEbToYQAmQ'; // $openid = $_SESSION['openid'];
$access_token = $_SESSION['access_token']; // $template_id = '5JCt5gNGM7sfwWnRqwWsjH138DixCFJ7sPEbToYQAmQ';
// $access_token = $_SESSION['access_token'];
file_put_contents($logFilePath, $openid, FILE_APPEND | LOCK_EX);
file_put_contents($logFilePath, "\n\r", FILE_APPEND | LOCK_EX); // file_put_contents($logFilePath, $openid, FILE_APPEND | LOCK_EX);
file_put_contents($logFilePath, $access_token, FILE_APPEND | LOCK_EX); // file_put_contents($logFilePath, "\n\r", FILE_APPEND | LOCK_EX);
// file_put_contents($logFilePath, $access_token, FILE_APPEND | LOCK_EX);
// test_sc
// 构造模板消息内容 // // test_sc
$template_data = array( // // 构造模板消息内容
'touser' => $openid, // $template_data = array(
'template_id' => $template_id, // 'touser' => $openid,
'url' => '', //点击模板消息跳转的URL // 'template_id' => $template_id,
'data' => array( // 'url' => '', //点击模板消息跳转的URL
'key1' => array('value' => 'value1'), // 'data' => array(
'key2' => array('value' => 'value2'), // 'key1' => array('value' => 'value1'),
'key3' => array('value' => 'value3'), // 'key2' => array('value' => 'value2'),
), // 'key3' => array('value' => 'value3'),
); // ),
// );
// 发送模板消息
$url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token; // // 发送模板消息
// $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // $ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1); // curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($template_data)); // curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($template_data));
$response = curl_exec($ch); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_close($ch); // $response = curl_exec($ch);
// curl_close($ch);
// 处理响应结果
if ($response === false) { // // 处理响应结果
// 模板消息发送失败 // if ($response === false) {
echo '发送模板消息失败!'; // // 模板消息发送失败
} else { // echo '发送模板消息失败!';
$result = json_decode($response, true); // } else {
if ($result['errcode'] == 0) { // $result = json_decode($response, true);
// 模板消息发送成功 // if ($result['errcode'] == 0) {
echo '发送模板消息成功!'; // // 模板消息发送成功
} else { // echo '发送模板消息成功!';
// 模板消息发送失败 // } else {
echo '发送模板消息失败!' . $result['errmsg']; // // 模板消息发送失败
} // echo '发送模板消息失败!' . $result['errmsg'];
} // }
// }
// 获取异步回调的数据 // 获取异步回调的数据
$postData = file_get_contents('php://input'); $postData = file_get_contents('php://input');
@ -90,7 +91,7 @@ file_put_contents($logFilePath, "here2\n\r", FILE_APPEND | LOCK_EX);
$new_plugin = new dalianpay(); $new_plugin = new dalianpay();
file_put_contents($logFilePath, "here3\n\r", FILE_APPEND | LOCK_EX); file_put_contents($logFilePath, "here3\n\r", FILE_APPEND | LOCK_EX);
$response_data = $new_plugin->query($postData); // $response_data = $new_plugin->query($postData);
// 添加时间戳和换行符 // 添加时间戳和换行符
$logMessage = date('Y-m-d H:i:s') . " - " . $response_data . "\n"; $logMessage = date('Y-m-d H:i:s') . " - " . $response_data . "\n";

Loading…
Cancel
Save