Giter Club home page Giter Club logo

wechatdeveloper's Introduction

WeChatDeveloper for PHP

Latest Stable Version Total Downloads Monthly Downloads Daily Downloads PHP Version Require License

  • WeChatDeveloper 是基于 wechat-php-sdk 重构,优化并完善;
  • 运行最底要求 PHP 版本 5.4 , 建议在 PHP7 上运行以获取最佳性能;
  • 目前 WeChatDeveloper 针对 access_token 失效增加了自动刷新机制;
  • 微信的部分接口需要缓存数据在本地,因此配置目录并需要对目录有写权限;
  • 我们鼓励大家使用 composer 来管理您的第三方库,方便后期更新操作;
  • WeChatDeveloper 已历经数个线上项目考验,欢迎 fork 或 star 此项目。
  • 微信商户已经支持 v2 和 v3 接口,未加入的接口可以使用通用方式调用。

功能描述

  • 微信小程序,服务端接口支持
  • 微信认证服务号,服务端接口支持
  • 微信支付(账单、卡券、红包、退款、转账、App支付、JSAPI支付、Web支付、扫码支付等)
  • 支付宝支付(账单、转账、App支付、刷卡支付、扫码支付、Web支付、Wap支付等)

技术帮助

PHP开发技术交流(QQ群 513350915)

PHP微信开发群 (SDK)

WeChatDeveloper 是基于官方接口封装,在做微信开发前,必需先阅读微信官方文档。

针对 WeChatDeveloper 也有一准备了帮助资料可供参考。

代码仓库

WeChatDeveloper 为开源项目,允许把它用于任何地方,不受任何约束,欢迎 fork 项目。

文件说明(后续会根据官方文档增加文件)

文件名 类名 描述 类型 加载 ①
App.php AliPay\App 支付宝App支付 支付宝支付 \We::AliPayApp()
Bill.php AliPay\Bill 支付宝账单下载 支付宝支付 \We::AliPayBill()
Pos.php AliPay\Pos 支付宝刷卡支付 支付宝支付 \We::AliPayPos()
Scan.php AliPay\Scan 支付宝扫码支付 支付宝支付 \We::AliPayScan()
Transfer.php AliPay\Transfer 支付宝转账 支付宝支付 \We::AliPayTransfer()
Wap.php AliPay\Wap 支付宝Wap支付 支付宝支付 \We::AliPayWap()
Web.php AliPay\Web 支付宝Web支付 支付宝支付 \We::AliPayWeb()
Card.php WeChat\Card 微信卡券接口支持 认证服务号 \We::WeChatCard()
Custom.php WeChat\Custom 微信客服消息接口支持 认证服务号 \We::WeChatCustom()
Media.php WeChat\Media 微信媒体素材接口支持 认证服务号 \We::WeChatMedia()
Oauth.php WeChat\Oauth 微信网页授权消息类接口 认证服务号 \We::WeChatOauth()
Pay.php WeChat\Pay 微信支付类接口 认证服务号 \We::WeChatPay()
Product.php WeChat\Product 微信商店类接口 认证服务号 \We::WeChatProduct()
Qrcode.php WeChat\Qrcode 微信二维码接口支持 认证服务号 \We::WeChatQrcode()
Receive.php WeChat\Receive 微信推送事件消息处理支持 认证服务号 \We::WeChatReceive()
Scan.php WeChat\Scan 微信扫一扫接口支持 认证服务号 \We::WeChatScan()
Script.php WeChat\Script 微信前端JSSDK支持 认证服务号 \We::WeChatScript()
Shake.php WeChat\Shake 微信蓝牙设备揺一揺接口 认证服务号 \We::WeChatShake()
Tags.php WeChat\Tags 微信粉丝标签接口支持 认证服务号 \We::WeChatTags()
Template.php WeChat\Template 微信模板消息接口支持 认证服务号 \We::WeChatTemplate()
User.php WeChat\User 微信粉丝管理接口支持 认证服务号 \We::WeChatCard()
Wifi.php WeChat\Wifi 微信门店WIFI管理支持 认证服务号 \We::WeChatWifi()
Draft.php WeChat\Draft 微信草稿箱 认证服务号 \We::WeChatDraft()
Freepublish.php WeChat\Freepublish 微信发布能力 认证服务号 \We::WeChatFreepublish()
Bill.php WePay\Bill 微信商户账单及评论 微信支付 \We::WePayBill()
Coupon.php WePay\Coupon 微信商户代金券 微信支付 \We::WePayCoupon()
Order.php WePay\Order 微信商户订单 微信支付 \We::WePayOrder()
Redpack.php WePay\Redpack 微信红包支持 微信支付 \We::WePayRedpack()
Refund.php WePay\Refund 微信商户退款 微信支付 \We::WePayRefund()
Transfers.php WePay\Transfers 微信商户打款到零钱 微信支付 \We::WePayTransfers()
TransfersBank.php WePay\TransfersBank 微信商户打款到银行卡 微信支付 \We::WePayTransfersBank()
Crypt.php WeMini\Crypt 微信小程序数据加密处理 微信小程序 \We::WeMiniCrypt()
Plugs.php WeMini\Plugs 微信小程序插件管理 微信小程序 \We::WeMiniPlugs()
Poi.php WeMini\Poi 微信小程序地址管理 微信小程序 \We::WeMiniPoi()
Qrcode.php WeMini\Qrcode 微信小程序二维码管理 微信小程序 \We::WeMiniCrypt()
Template.php WeMini\Template 微信小程序模板消息支持 微信小程序 \We::WeMiniTemplate()
Total.php WeMini\Total 微信小程序数据接口 微信小程序 \We::WeMiniTotal()

安装使用

1.1 通过 Composer 来管理安装

# 首次安装 线上版本(稳定)
composer require zoujingli/wechat-developer

# 首次安装 开发版本(开发)
composer require zoujingli/wechat-developer dev-master

# 更新 WeChatDeveloper
composer update zoujingli/wechat-developer

1.2 如果不使用 Composer, 可以下载 WeChatDeveloper 并解压到项目中

# 在项目中加载初始化文件
include "您的目录/WeChatDeveloper/include.php";

2.1 接口实例所需参数

$config = [
    'token'          => 'test',
    'appid'          => 'wx60a43dd8161666d4',
    'appsecret'      => '71308e96a204296c57d7cd4b21b883e8',
    'encodingaeskey' => 'BJIUzE0gqlWy0GxfPp4J1oPTBmOrNDIGPNav1YFH5Z5',
    // 配置商户支付参数(可选,在使用支付功能时需要)
    'mch_id'         => "1235704602",
    'mch_key'        => 'IKI4kpHjU94ji3oqre5zYaQMwLHuZPmj',
    // 配置商户支付双向证书目录(可选,在使用退款|打款|红包时需要)
    'ssl_key'        => '',
    'ssl_cer'        => '',
    // 缓存目录配置(可选,需拥有读写权限)
    'cache_path'     => '',
];

3.1 实例指定接口

try {

    // 实例对应的接口对象
    $user = new \WeChat\User($config);
    
    // 调用接口对象方法
    $list = $user->getUserList();
    
    // 处理返回的结果
    echo '<pre>';
    var_export($list);
    
} catch (Exception $e) {

    // 出错啦,处理下吧
    echo $e->getMessage() . PHP_EOL;
    
}

微信支付

  // 创建接口实例
  $wechat = new \WeChat\Pay($config);
  
  // 组装参数,可以参考官方商户文档
  $options = [
      'body'             => '测试商品',
      'out_trade_no'     => time(),
      'total_fee'        => '1',
      'openid'           => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo',
      'trade_type'       => 'JSAPI',
      'notify_url'       => 'http://a.com/text.html',
      'spbill_create_ip' => '127.0.0.1',
  ];
    
try {

    // 生成预支付码
    $result = $wechat->createOrder($options);
    
    // 创建JSAPI参数签名
    $options = $wechat->createParamsForJsApi($result['prepay_id']);
    
    // @todo 把 $options 传到前端用js发起支付就可以了
    
} catch (Exception $e) {

    // 出错啦,处理下吧
    echo $e->getMessage() . PHP_EOL;
    
}
  • 更多功能请阅读测试代码或SDK封装源码

支付宝支付

  • 支付参数配置(可用沙箱模式)
$config = [
    // 沙箱模式
    'debug'            => true,
    // 签名类型 ( RSA|RSA2 )
    'sign_type'        => 'RSA2',
    // 应用ID
    'appid'            => '2021000122667306',
    // 应用私钥内容 ( 需1行填写,特别注意:这里的应用私钥通常由支付宝密钥管理工具生成 )
    'private_key'      => 'MIIEowIBAAKCAQEAn...',
    // 公钥模式,支付宝公钥内容 ( 需1行填写,特别注意:这里不是应用公钥而是支付宝公钥,通常是上传应用公钥换取支付宝公钥,在网页可以复制 )
    'public_key'       => '',
    // 证书模式,应用公钥证书路径 ( 新版资金类接口转 app_cert_sn,如文件 appCertPublicKey.crt )
    'app_cert_path'    => __DIR__ . '/alipay/appPublicCert.crt', // 'app_cert' => '证书内容',
    // 证书模式,支付宝根证书路径 ( 新版资金类接口转 alipay_root_cert_sn,如文件 alipayRootCert.crt )
    'alipay_root_path' => __DIR__ . '/alipay/alipayRootCert.crt', // 'root_cert' => '证书内容',
    // 证书模式,支付宝公钥证书路径 ( 未填写 public_key 时启用此参数,如文件 alipayPublicCert.crt )
    'alipay_cert_path' => __DIR__ . '/alipay/alipayPublicCert.crt', // 'public_key' => '证书内容'
    // 支付成功通知地址
    'notify_url'       => '',
    // 网页支付回跳地址
    'return_url'       => '',
];
  • 支付宝发起PC网站支付
// 参考公共参数  https://docs.open.alipay.com/203/107090/
$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';

try {
    
    // 实例支付对象
    $pay = We::AliPayWeb($config);
    // $pay = new \AliPay\Web($config);
    
    // 参考链接:https://docs.open.alipay.com/api_1/alipay.trade.page.pay
    $result = $pay->apply([
        'out_trade_no' => time(), // 商户订单号
        'total_amount' => '1',    // 支付金额
        'subject'      => '支付订单描述', // 支付订单描述
    ]);
    
    echo $result; // 直接输出HTML(提交表单跳转)
    
} catch (Exception $e) {

    // 异常处理
    echo $e->getMessage();
    
}
  • 支付宝发起手机网站支付
// 参考公共参数  https://docs.open.alipay.com/203/107090/
$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';

try {

    // 实例支付对象
    $pay = We::AliPayWap($config);
    // $pay = new \AliPay\Wap($config);

    // 参考链接:https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
    $result = $pay->apply([
        'out_trade_no' => time(), // 商户订单号
        'total_amount' => '1',    // 支付金额
        'subject'      => '支付订单描述', // 支付订单描述
    ]);

    echo $result; // 直接输出HTML(提交表单跳转)

} catch (Exception $e) {

    // 异常处理
    echo $e->getMessage();

}
  • 更多功能请阅读测试代码或SDK封装源码

版权说明

WeChatDeveloper 遵循 MIT 开源协议发布,并免费提供使用。

本项目包含的第三方源码和二进制文件的版权信息将另行标注,请在对应文件查看。

版权所有 Copyright © 2014-2023 by ThinkAdmin (https://thinkadmin.top) All rights reserved。

赞助打赏,请作者喝杯茶 ~

赞助

wechatdeveloper's People

Contributors

big-dream avatar fangxiaotao avatar gaoyiping avatar humengcn avatar imzhi avatar innovational avatar kentwangit avatar pkkgu avatar qfz9527 avatar rootrl avatar voilaf avatar zoujingli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wechatdeveloper's Issues

订阅消息接口

image

模板消息已准备下线,希望实现一下订阅消息接口,谢谢!

local cache error.

Type: WeChat\Exceptions\LocalCacheException
Message: local cache error.
File: /home/xxx.cn/vendor/zoujingli/wechat-developer/WeChat/Contracts/Tools.php
Line: 271

开放平台获取access_token的时候提示 ticket 不对

如果开放平台的access_token过期了,再去请求access_token的时候就会发生下面的错误
component ticket is invalid hint: [f7sdKA0009hb96]
然后过了几分钟,就神奇般的又可以正常获取access_token了。?
微信推送的component_verify_ticket这个包已经保存进设置的存储目录了啊,数据库也相应更新了。不知道为啥会出这种错误。求解答

Tools::arr2json 能否加参数,不转移Emoji标签

因为数据表里都是utf8mb4保存的,在提取后用客户消息时,会被Tools::emojiEncode转义,导致用户收到的都是\uexxxx码,Custom::send里也不支持直接发送自己的json,而一定要数组才行,好像只能继承类,覆盖send函数,弃用httpPostForJson,但发现httpPostForJson使用的地方很多不清楚会不会还有其他地方会涉及到。

关于获取AccessToken方法的修改建议

/**
* 通过 code 获取 AccessToken 和 openid
* @return bool|array
* @throws Exceptions\InvalidResponseException
*/
public function getOauthAccessToken()
{
$appid = $this->config->get('appid');
$appsecret = $this->config->get('appsecret');
$code = isset($_GET['code']) ? $_GET['code'] : '';
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code";
return $this->httpGetForJson($url);
}

建议这个方法用到的code能可以改成使用参数传递。在前后端完全分离开发时,code不一定是通过get方法提交的,用参数传递会比较灵活。

你好,使用sdk给小程序做支付的时候提示签名错误问题

// 3. 创建接口实例
$wechat = new Pay(WxappConfig::getConfig());

    // 4. 组装参数,可以参考官方商户文档
    $options = [
        'body' => '充值',
        'out_trade_no' => OrderService::createOrderSn($userId, $money, '充值'),
        'total_fee' => (int) ($money * 100), //金额转成分
        'openid' => $aUserInfo['openid'],
        'trade_type' => 'JSAPI',
        'notify_url' => url('@api/Notify/payCallback', '', true, true),
            //'spbill_create_ip' => '127.0.0.1',
    ];
    //获取预支付码
    $prepay = $wechat->createOrder($options);
    $result = $wechat->createParamsForJsApi($prepay['prepay_id']);

调用顺序是这样的,发现一个大坑,如果是这样调用小程序发起支付一致都会签名校验出错,改正

修改楼主默认的pay.php中的
/**
* 统一下单
* @param array $options
* @return array
* @throws InvalidResponseException
*/
public function createOrder(array $options, $signType = "MD5") {
$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
return $this->callPostApi($url, $options, false, $signType);
}
注意是$signType 这个大坑修复,注意签名类型

你好,调用小程序生成二维码的时候。返回json,竟然吧图片也输入出去了

/vendor/zoujingli/wechat-developer/WeMini/Qrcode.php:84:string '�PNG
�
���
IHDR������������������ �IDATx�����܇���ωo���Sl1��)Tl���)4��+�b�ҁ ���.Cd�*��#W����⸃H���ʠC�]��s�A��XH1[la��M!�/<����~n�7�M�x����������J����ߓ+mlll|O������=��������J����ߓ+mlll|O������=��������J��?0�8�Z��x�
ml�@����Ǐ�O�>�w~~޵k׎o޼y�6����V�;���C��ŋ�?��?��x�?�������=������m��������駟�;==�k�8����///�x;]ic������?�|>�c�;==m�Z��x+]ic�����rqrr�7ݸq��tz��[�J�?z�ժq�{����tyy��ah:�������ih�G���l����{'''��t�����߸qc1Co�?����.//{�t:��w�}��[kh�G��Ç�~����q���?~|�ڵkdz�츷���e'''}�d2i2���������'... (length=51401)
{"status":"success","msg":"生成二维码成功","data":"jay"}

更改卡券信息接口bug,并非固定为member_card类型,应该是根据卡券的类型来定义

/** * 更改卡券信息接口 * @param string $card_id * @param array $member_card * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ public function updateCard($card_id, array $member_card) { $url = "https://api.weixin.qq.com/card/update?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, ['card_id' => $card_id, 'member_card' => $member_card]); }

member_card 传参应该由传入者根据卡券类型定义。
//填写该cardid相应的卡券类型(小写)。

以下为官方文档

{ "card_id":"ph_gmt7cUVrlRk8swPwx7aDyF-pg", "member_card": { //填写该cardid相应的卡券类型(小写)。 "base_info": { "logo_url": "http:\/\/www.supadmin.cn\/uploads\/allimg\/120216\/1_120216214725_1.jpg", "color": "Color010", "notice": "使用时向服务员出示此券", "service_phone": "020-88888888", "description": "不可与其他优惠同享\n如需团购券发票,请在消费时向商户提出\n店内均可使用, 仅限堂食\n餐前不可打包,餐后未吃完,可打包\n本团购券不限人数,建议2人使用, 超过建议人数须另收酱料费5元/位\n本单谢绝自带酒水饮料" "location_id_list" : [123, 12321, 345345] }, "bonus_cleared": "aaaaaaaaaaaaaa", "bonus_rules": "aaaaaaaaaaaaaa", "prerogative": "" } }

access_token缓存位置

查看代码得知access_token缓存是file,Tool的cache是否以后会支持redis或memcache?

统一订单和 JSAPI 的签名算法不同导致 chooseWXPay 调用失败?

这个版本的 Pay.php 创建预支付订单使用的默认签名算法和生成支付签名的所使用的默认签名算法不一样,而这可能会导致调用 chooseWXPay 时报签名错误。
_20180430001523
_20180430001541
创建预支付订单默认使用的是 HMAC-SHA256 算法

_20180430001651
生成支付签名默认使用的是 MD5 算法

微信的文档里面似乎也没有提到这两者的不一致会导致签名验证失败,我在调用 getPaySign 是指定使用 HMAC-SHA256 算法, chooseWXPay 顺利调用。

不知道这里面是否有什么误会。如果确实是因为两个地方使用的算法不一样而导致签名验证失败,希望作者能将两者的算法改成一样。
因为。。。。微信的文档真的太难读了!!!。。。。我试了一整天才发现这个现象。

不支持支付宝App支付

不支持支付宝App支付
位置:vendor/zoujingli/wechat-developer/AliPay/App.php
方法:public function apply($options)
{
$this->applyData($options);
return http_build_query($this->options->get());
}

**镜像,版本少一个1.1.3

你好,因为国外的速度问题,一般使用packagist.phpcomposer.com作为源。发现少一个1.1.3的版本,麻烦你能自己写一个hook自己更新一下这个镜像。谢谢

一个奇怪的问题

发现一个奇怪的问题,用最新版覆盖后,整个就不工作了.必须注释这样的:throw new InvalidResponseException($e->getMessage(), $e->getCode());,才能正常工作?是什么原因呢?linux+php5.6.

tp5.1 下载引入报错了

下载了zip包后 放到了vendor文件夹下,使用的时候用了include 'vendor/WeChatDeveloper/include.php'; 这样的一行代码 然后api请求的时候报错:
[2] ErrorException in Payment.php line 22
include(vendor/WeChatDeveloper/include.php): failed to open stream: No such file or directory

建议添加验证支付宝异步支付通知验证

建议添加验证支付宝异步支付通知验证

参考代码:

    public function verify2($data, $sign = null, $sync = false)
    {
        if (is_null($this->config->get('ali_public_key'))) {
            throw new InvalidArgumentException('Missing Config -- [ali_public_key]');
        }
        $sign = is_null($sign) ? $data['sign'] : $sign;
        $data['sign'] = null;
        $data['sign_type'] = null;
        $content = wordwrap($this->config->get('ali_public_key'), 64, "\n", true);
        $string = $sync ? json_encode($data) : $this->getSignContent($data, true);
        $res = "-----BEGIN PUBLIC KEY-----\n{$content}\n-----END PUBLIC KEY-----";
        return (bool)openssl_verify($string, base64_decode($sign), $res, OPENSSL_ALGO_SHA256);
    }

说明:
异步通知用的是支付宝公钥,之前的验证是应用公钥,要在配置文件中加入支付宝公钥。
将返回数据中sign 和 sign_type 置空。

支付宝当面付API问题

我在测试当面付时,出现这个错误

ResultError
Service Currently Unavailable[20000]
系统繁忙[aop.unknow-error]

经过查找和百度,应该是和支付宝服务器的连接方式问题。

BasicAliPay.php 199 行

$data = json_decode(Tools::post($this->gateway, $this->options->get()), true);

你是用post方式提交的

我改为 get 方式提交后错误消失了。

$data = json_decode(Tools::get($this->gateway, $this->options->get()), true);

不知道是不是这个问题,改的对不对,希望你看一下。

申请退款的方法调用了统一下单的方法,咦~~~~

作者不靠谱啊 更bug出来 /** * 申请退款 * @param array $options * @return array * @throws Exceptions\LocalCacheException * @throws InvalidResponseException */ public function createRefund(array $options) { return Order::instance($this->config->get())->create($options); } /** * 查询退款 * @param array $options * @return array * @throws Exceptions\LocalCacheException * @throws InvalidResponseException */ public function queryRefund(array $options) { return Order::instance($this->config->get())->query($options); } #@https://github.com/zoujingli/WeChatDeveloper/blob/master/WeChat/Pay.php
申请退款的接口怎么就变成了统一下单了呢

php 5.6 微信错误 麻烦修复

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in E:\xampp\htdocs\TWCloud\vendor\zoujingli\wechat-developer\WeChat\Contracts\Tools.php on line 277

\zoujingli\wechat-developer\WeChat\Contracts\Tools.php

第277行 $data[$key] = ($myCurlFile = new MyCurlFile((array)$value))->get();

修改为
$myCurlFile = new MyCurlFile((array)$value);
$data[$key] = $myCurlFile->get();

验签失败仍转账成功

支付宝AliPayTransfer()接口,public_key没有使用支付宝的公共key,用了自己的key,提示“Data signature verification failed”,这个是正确的。但是看转账记录,却发现转账成功了。是不是应该修复一下,这个时候不给转账。

code been used

n uncaught Exception was encountered
Type: WeChat\Exceptions\InvalidResponseException

Message: code been used, hints: [ req_id: FfhfgP.Ce-9Wexoa ]

Filename: /data/home/qxu1142170109/htdocs/ygcj/application/vendor/zoujingli/wechat-developer/WeChat/Contracts/BasicWeChat.php

Line Number: 177

Backtrace:

File: /data/home/qxu1142170109/htdocs/ygcj/application/vendor/zoujingli/wechat-developer/WeChat/Oauth.php
Line: 54
Function: httpGetForJson

File: /data/home/qxu1142170109/htdocs/ygcj/application/controllers/Wx.php
Line: 63
Function: getOauthAccessToken

File: /data/home/qxu1142170109/htdocs/ygcj/index.php
Line: 315
Function: require_once


用的ci框架,composer安装在application目录下,配置已开启自动引入

config = array( 'token' => 'aaaa', // 填写你设定的key 'appid' => 'aaaa', // 填写高级调用功能的app id, 请在微信开发模式后台查询 'appsecret' => 'aaaa', // 填写高级调用功能的密钥 'encodingaeskey' => '', // 填写加密用的EncodingAESKey(可选,接口传输选择加密时必需) 'mch_id' => '', // 微信支付,商户ID(可选) 'partnerkey' => '', // 微信支付,密钥(可选) 'ssl_cer' => '', // 微信支付,双向证书(可选,操作退款或打款时必需) 'ssl_key' => '', // 微信支付,双向证书(可选,操作退款或打款时必需) 'cachepath' => '', // 设置SDK缓存目录(可选,默认位置在Wechat/Cache下,请保证写权限) ); $this->load->model("wx_model"); } public function index() { // 实例接口,同时实现接口配置验证与解密处理 $api = new \WeChat\Receive($this->config); // 第二种方法实例接口 // $api = \We::WeChatReceive($this->config); // 获取当前推送接口类型 ( text,image,loction,event... ) $msgType = $api->getMsgType(); // 获取当前推送来源用户的openid $openid = $api->getOpenid(); // 获取当前推送的所有数据 $data = $api->getReceive(); // 回复文本消息 $api->text("http://www.aaa.com/ygcj/index.php/wx/bind")->reply(); } public function bind() { // 实例接口 $wechat = new \WeChat\Oauth($this->config); // 执行操作 $result = $wechat->getOauthRedirect("http://www.aaa.com/ygcj/index.php/wx/bind_callback"); redirect($result); } public function bind_callback() { // 实例接口 $wechat = new \WeChat\Oauth($this->config); // 执行操作 $res = $wechat->getOauthAccessToken(); //有时可以,有时提示code been used if($res===FALSE){ echo "getOauthAccessToken false"; } $openid = $res["openid"]; $rows = $this->wx_model->get_custom_by_openid($openid); if(count($rows) == 0) { $data = array('openid' => $openid); $this->load->view("bind", $data); return; } } }

支付宝网站支付问题

首先,很感谢你写的这套sdk。

支付宝 pc 端支付代码有一点问题。

刚开始的时候直接使用你的代码,出现缺少‘method’错误:

错误代码 missing-method 错误原因: 缺少方法名参数

支付宝配置和商品描述都没有问题,使用的是正式环境。

后来我下载官方的demo,比较你生成的html和他们生成的html代码,发现你生成的代码 input 少了很多参数,原来你就把 params 参数放进去了,option里面的参数没有加进去。

我直接在下面加了一个循环(vendor\zoujingli\wechat-developer\WeChat\Contracts\BasicAliPay.php:226行左右)

foreach ($this->options->get() as $key => $value) {
            $value = str_replace("'", '&apos;', $value);
            $html .= "<input type='hidden' name='{$key}' value='{$value}'/>";
        }

出现验签错误:

错误代码 invalid-signature 错误原因: 验签出错,建议检查签名字符串或签名私钥与应用公钥是否匹配,网关生成的验签字符串为:

仔细比较生成的html代码,原来 product_code 参数是放在 biz_content 参数里面的。

最终修改如下:
vendor\zoujingli\wechat-developer\WeChat\Contracts\BasicAliPay.php 186行:

$this->options['biz_content'] = json_encode(array_merge($options, $this->params->get()), 
JSON_UNESCAPED_UNICODE);

222 行 :

// foreach ($this->params->get() as $key => $value) {
        //     $value = str_replace("'", '&apos;', $value);
        //     $html .= "<input type='hidden' name='{$key}' value='{$value}'/>";
        // }
        foreach ($this->options->get() as $key => $value) {
            $value = str_replace("'", '&apos;', $value);
            $html .= "<input type='hidden' name='{$key}' value='{$value}'/>";
        }

成功调起支付宝pc支付界面。

其他模式未测试。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.