微信小程序支付报错:JSAPI支付必须传openid

微信小程序 · Fecmall · 于 3年前 发布 · 9367 次阅读

fecmall微信小程序入口,支付的时候报错: JSAPI支付必须传openid

经过排查,这个是fecmall的新版修复一个bug导致的问题,微信小程序的openId取值,取得是微信公众号的

现在已经修复,详细参看:https://github.com/fecshop/yii2_fecshop/commit/ca85263a39f4ddca6c9c6f0b732b1c4c0d1e8756

vendor/fancyecommerce/fecshop/services/payment/WxpayMicro.php 173行

$openId = $identity->wx_openid;

改为:

$openId = $identity->wx_micro_openid;

可以自行修改文件,或者等fecmall发新版本。

共收到 11 条回复
johocn#13年前 0 个赞

按照上述使用说明修改依然报错,原因是$identity->wx_micro_openid的值是空的,其他如id,phone等值正常。 需要设置一下Yii::$app->user->identity返回的字段,不知在哪设置?

Fecmall#23年前 0 个赞

这是老帖子了,已经发版了

新的版本不需要改。

johocn#33年前 0 个赞

Yii::$app->user->identity返回的字段没有$identity->wx_micro_openid的值,需要检查哪个文件?

Fecmall#43年前 0 个赞

@johocn #3楼 你是不是版本很老了? customer表没有这个字段?

johocn#53年前 0 个赞

customer表有相关字段,Yii::$app->user->identity对象里私有对象里有$identity->wx_micro_openid,但是公有对象里没有,$identity->wx_micro_openid的值是空的,其他如$identity->id,$identity->phone等值正常。我觉得是不是我的Yii::$app->user->identity这个相关文件不全.我用composer update 更新了,没有变化.我没升级当前最高版本,我的版本2.8.4

Fecmall#63年前 0 个赞

1.你换个微信账户测试试试?

2.或者你清空一下你的账户表:customer,另外清空一下表:customer_wx_qr_code_log

重新注册试试?测试试试

Fecmall#73年前 0 个赞

微信支付这个,您自己debug一下代码试试把,如果某些函数找不到代码位置,可以发帖求助一下,我给你找找文件路径。

您自己debug一下吧,本地无法复现,无法精准解决,还是得靠你自己debug一下代码。

johocn#93年前 0 个赞
   //①、获取用户openid
        $tools = new \JsApiPay();
        $identity = Yii::$app->user->identity;
        $openId = $identity->wx_micro_openid;

主要是$identity->wx_micro_openid没有值,其他$identity->id,$identity->phone等都有值

我要Yii::$app->user->identity这个函数的位置.

Fecmall#103年前 0 个赞

Yii::$app->user->identity 这个是yii2的组件

就是customer对应的内容,如果没有值,就说明你的数据表customer里面没有值

johocn#113年前 0 个赞

https://github.com/fecshop/yii2_fecshop/blob/master/services/payment/WxpayMicro.php

在以上文件中添加如下语句:

        var_dump($order);
        echo '<br>===';
        var_dump($identity);
        echo '<br>==='.$identity->phone .'<br>==='.$identity->wx_micro_openid;
        exit();

返显信息如下:

array(10) { ["appid"]=> string(18) "隐藏" ["device_info"]=> string(4) "1000" ["err_code"]=> string(11) "PARAM_ERROR" ["err_code_des"]=> string(26) "JSAPI支付必须传openid" ["mch_id"]=> string(10) "隐藏" ["nonce_str"]=> string(16) "PewQgH4ihkniLh3K" ["result_code"]=> string(4) "FAIL" ["return_code"]=> string(7) "SUCCESS" ["return_msg"]=> string(2) "OK" ["sign"]=> string(32) "38002EE7C02E27B90CDCF10F8A77AF5B" } 


===object(fecshop\models\mysqldb\Customer)#153 (10) { ["_attributes":"yii\db\BaseActiveRecord":private]=> array(28) { ["id"]=> int(12) ["email"]=> NULL ["phone"]=> string(11) "138044隐藏" ["firstname"]=> NULL ["lastname"]=> NULL ["is_subscribed"]=> int(2) ["status"]=> int(1) ["birth_date"]=> NULL ["favorite_product_count"]=> int(0) ["type"]=> string(7) "default" ["access_token_created_at"]=> int(1611237760) ["allowance"]=> NULL ["allowance_updated_at"]=> NULL ["wx_password_is_set"]=> int(2) ["wallet"]=> string(4) "0.00" ["group_id"]=> NULL ["console_add_group"]=> int(1) ["point"]=> string(4) "0.00" ["customer_code"]=> NULL ["customer_parent_id"]=> NULL ["is_distribute"]=> int(1) ["distribute_wallet"]=> string(4) "0.00" ["distribute_group_id"]=> NULL ["distribute_status"]=> int(1) ["distribute_code"]=> string(36) "36470588-508a-11eb-b225-隐藏" ["distribute_created_at"]=> int(1609984011) ["distribute_parent_id"]=> NULL ["distribute_phone"]=> string(11) "隐藏" } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(42) { ["id"]=> int(12) ["password_hash"]=> string(60) "隐藏" ["password_reset_token"]=> NULL ["register_enable_token"]=> NULL ["email"]=> NULL ["phone"]=> string(11) "138044隐藏" ["firstname"]=> NULL ["lastname"]=> NULL ["is_subscribed"]=> int(2) ["auth_key"]=> string(32) "_mog0Grn85隐藏" ["status"]=> int(1) ["created_at"]=> int(1606028410) ["updated_at"]=> int(1606028410) ["password"]=> string(0) "" ["access_token"]=> string(32) "1ZLa51yK_隐藏" ["birth_date"]=> NULL ["favorite_product_count"]=> int(0) ["type"]=> string(7) "default" ["access_token_created_at"]=> int(1611237760) ["allowance"]=> NULL ["allowance_updated_at"]=> NULL ["wx_session_key"]=> string(24) "7ttZd隐藏" ["wx_openid"]=> NULL ["wx_micro_openid"]=> string(28) "oUDEQ0YzOXlfCg6kvktj2_隐藏" ["wx_password_is_set"]=> int(2) ["customer_bank"]=> NULL ["customer_bank_name"]=> NULL ["customer_bank_account"]=> NULL ["wallet"]=> string(4) "0.00" ["group_id"]=> NULL ["console_add_group"]=> int(1) ["point"]=> string(4) "0.00" ["customer_code"]=> NULL ["customer_parent_id"]=> NULL ["is_distribute"]=> int(1) ["distribute_wallet"]=> string(4) "0.00" ["distribute_group_id"]=> NULL ["distribute_status"]=> int(1) ["distribute_code"]=> string(36) "36470588-508a-11eb-b2隐藏c" ["distribute_created_at"]=> int(1609984011) ["distribute_parent_id"]=> NULL ["distribute_phone"]=> string(11) "1380隐藏" } ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_relationsDependencies":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(0) { } ["_eventWildcards":"yii\base\Component":private]=> array(0) { } ["_behaviors":"yii\base\Component":private]=> array(0) { } } 

===138044隐藏

===

隐藏处是部分数字或字符

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics