<?php require __DIR__ . '/../vendor/autoload.php'; use PFinal\Wechat\Kernel; use PFinal\Wechat\Message\Receive; use PFinal\Wechat\Support\Log; use PFinal\Wechat\Message; use PFinal\Wechat\WechatEvent; //请复制 config-local.example 为 config-local.php $config = (require __DIR__ . '/config-local.php'); Kernel::init($config); //注册事件消息处理函数 Kernel::register(Receive::TYPE_TEXT, function (WechatEvent $event) { $message = $event->getMessage(); include __DIR__ . '/test-data.php'; // 一些测试用的数据 Log::debug('收到请求', (array) $message); switch ($message->Content) { case 'hi': $event->setResponse('你好'); break; case 'image': $event->setResponse(new \PFinal\Wechat\Message\Image($imageMediaId)); break; case 'news': //$event->setResponse(new \PFinal\Wechat\Message\News('pFinal社区', '致力于提供优质PHP中文学习资源', 'http://www.pfinal.cn/', 'http://www.pfinal.cn/images/pfinal.png')); $event->setResponse(new \PFinal\Wechat\Message\News($news)); break; case 'music': $event->setResponse(new \PFinal\Wechat\Message\Voice($voiceMediaId)); break;
<?php require __DIR__ . '/../vendor/autoload.php'; $config = array('appId' => 'wx00e5904efes9', 'appSecret' => '419ffc73eb1fga846c6b04b', 'token' => '54b780cbe9047', 'encodingAesKey' => 'cz7NR8g4vk5yMydpG3g8amyFGbjavCuR33', 'mchId' => '1220633201', 'apiSecret' => 'b4944959c6eaed319a86e3a10d'); // 初始化SDK \PFinal\Wechat\Kernel::init($config); // 获取OpenID $openid = \PFinal\Wechat\Service\OAuthService::getOpenid(); //$openid='oU3OCt5O46PumN7IE87WcoYZY9r0'; // JS签名 $signPackage = \PFinal\Wechat\Service\JsService::getSignPackage(); // 支付成功通知url /* 收到支付成功通知时,请使用下面的方法,验证订单号和支付金额 $info = \PFinal\Wechat\Service\PayService::notify(); $info数组,内容如下 [ mch_id //微信支付分配的商户号 appid //微信分配的公众账号ID openid //用户在商户appid下的唯一标识 transaction_id //微信支付订单号 out_trade_no //商户订单号 total_fee //订单总金额单位默认为分,已转为元 is_subscribe //用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效 attach //商家数据包,原样返回 time_end //支付完成时间 ] */ $notifyUrl = 'http://xxx.com/index.php/wxpay/notify'; // 订单信息 $order = array('totalFee' => 0.01, 'tradeNo' => uniqid(), 'name' => '测试订单'); // 业务签名