Closed gilles6 closed 6 years ago
$result = $payment->order->unify([
'trade_type' => 'JSAPI',
'body' => 'MY BODY',
'detail' => 'MY DETAILS',
'out_trade_no' => 'MYERPORDERID12345680',
'total_fee' => 1.01,
'spbill_create_ip' => '120.76.101.172',
'openid' => 'wxd37384b6a45b69ac',
'notify_url' => url('xxxxx') // <------ here
]);
Thanks for your fast answer!
I have add 'notify_url' => url('http://my.website.com/payments/wechat-notify')
but I still get an empty array and the notify_url
is not called. What else could be wrong ?
用浏览器打开my.website.com/wechat
的时候,wechat.log
里面没什么新的日志。
$ tail -f storage/logs/wechat.log
unify 传入的数组值怎么检查结果?
我用的Apache日志里没看到什么异常的。
另外,notify_url
我也不确定要用下面的哪个,放在我的Controller里面好,还是放在config/wechat.php好?
WeChatController.php
public function serve()
{
Log::info('request arrived.');
$payment = EasyWeChat::payment('default');
$result = $payment->order->unify([
'trade_type' => 'JSAPI',
'body' => 'MY BODY',
'detail' => 'MY DETAILS',
'out_trade_no' => 'MYERPORDERID12345680',
'total_fee' => 1.01,
'spbill_create_ip' => '120.76.101.172',
'openid' => 'wxd37384b6a45b69ac',
// 'notify_url' => url('https://pay.weixin.qq.com/wxpay/pay.action')
'notify_url' => url('http://my.website.com/payments/wechat-notify')
]);
Log::info($result);
return $result;
}
config/wechat.php
return [
...
'payment' => [
'default' => [
'sandbox' => env('WECHAT_PAYMENT_SANDBOX', true),
'app_id' => env('WECHAT_PAYMENT_APPID', 'wxd373c'),
'mch_id' => env('WECHAT_PAYMENT_MCH_ID', '12341'),
'key' => env('WECHAT_PAYMENT_KEY', 'H8H06Z721qs345U6q62c786433KCC68D'),
'cert_path' => env('WECHAT_PAYMENT_CERT_PATH', '/Users/me/code/wechat_cert/apiclient_cert.pem'),
'key_path' => env('WECHAT_PAYMENT_KEY_PATH', '/Users/me/code/wechat_cert/apiclient_key.pem'),
// 'notify_url' => env('http://my.website.com/payments/wechat-notify'),
// 'notify_url' => env('https://pay.weixin.qq.com/wxpay/pay.action'),
],
],
检查一下 app/Http/Middleware/VerifyCsrfToken.php
protected $except = [ ]
,有没除掉你的 notify
路由;
@devondahon 请不要直接粘贴敏感信息
@devondahon 你是在服务器上调试的吧?不是本地吧
@almas1992
$ cat app/Http/Middleware/VerifyCsrfToken.php
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
'wechat',
];
}
@overtrue 没放敏感信息,信息都是假的。我是在本地编码然后git push之后在服务器上面看结果。
另外,app_id和openid写的是一样。 我是在这里找到了app_id: pay.weixin.qq.com > 营销中心 > 支付后配置 > 发起支付的appid 这个网站上没找到openid。
appid 是公众号 id...
说错了,不好意思,我的意思是openid在pay.weixin.qq.com里找不到。
@devondahon openid 当然在那里找不到啊,那明明是公众号的东西
Sorry, my Chinese is limited.
Do I have to set the openid in $payment->order->unify([...]) and, if yes, where should I get it from ?
I made a request to your QQ group, it's maybe a better place to talk about my empty array problem before posting the solution here.
You can get openid from wechat server push message FromUserName
or OAuth login result.
What I need first is to display a payment QR code in the browser. Should this QR code be requested with EasyWechat ?
https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_1
https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1
create product scheme:
$payment->scheme($productId)
// $productId is your database product id
weixin://wxpay/bizpayurl?xxxxxxx=xxxx
create QR code using your favorite library with scheme result.
user scan the QR
wechat notify your server by the url your configured from pay.wx.qq.com
admin panel.
handle the notify, you will get openid
and product id
from notify body. and create order by unify
method. return the response.
user completed pay.
notify you the result.
So, you must be read the official docs and know the logic.
Thanks for the references.
Could you please provide some code examples ?
Like this one: https://hotexamples.com/examples/overtrue.wechat/Payment/-/php-payment-class-examples.html Bu this one seems to concern an older version of EasyWeChat. Most examples I found on Google are outdated unfortunately.
@devondahon 对不起,也许你需要自己找身边中文熟悉的朋友帮忙你详细阅读理解微信官方的文档,我工作繁忙,没有时间帮忙哦。抱歉。
Nevermind. Thanks for your help!
@overtrue 我终于明白了!手机里打开公众号发消息的时候,服务器那边都有日志了。 非常感谢你耐心,也非常感谢你提供的这个工具!
@devondahon 是的
@devondahon 不客气
I'm getting an empty array when my WeChatController is called, not even an error message, and the notify() is not called. What's wrong my code ?
web.php