Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

退款接口,证书是怎么使用呢? #312

Closed
MIA503 opened this issue Dec 4, 2017 · 6 comments
Closed

退款接口,证书是怎么使用呢? #312

MIA503 opened this issue Dec 4, 2017 · 6 comments

Comments

@MIA503
Copy link
Contributor

MIA503 commented Dec 4, 2017

微信退款时证书该怎么使用呢?

  • 我们文档里,创建WeChatPay对象时会填商户证书路径和商户证书私钥路径。我是直接填写了证书在服务器上的路径, 如 /cert/apiclient_cert.p12,可是会报错
OSError: Could not find the TLS certificate file, invalid path: /cert/apiclient_cert.p12

[('PEM routines', 'PEM_read_bio', 'no start line'), ('SSL routines', 'SSL_CTX_use_certificate_file', 'PEM lib')]
class WeChatPay(object):
    """
    微信支付接口

    :param appid: 微信公众号 appid
    :param api_key: 商户 key
    :param mch_id: 商户号
    :param sub_mch_id: 可选,子商户号,受理模式下必填
    :param mch_cert: 必填,商户证书路径
    :param mch_key: 必填,商户证书私钥路径
    """
@LKI
Copy link
Collaborator

LKI commented Dec 4, 2017

给的信息不足,可以尝试以下几个方式:

  • 文件是否放对位置了
  • key 文件是否正确
  • 文件有没有放反

@LKI LKI closed this as completed Dec 4, 2017
@messense
Copy link
Member

messense commented Dec 4, 2017

提供更多信息后可以 reopen 这个 issue. never mind.

@messense
Copy link
Member

messense commented Dec 4, 2017

目前不支持 p12 的证书,请使用 pem 格式的证书和 key.

Blocked by psf/requests#1573

@MIA503
Copy link
Contributor Author

MIA503 commented Dec 4, 2017

实名感谢大佬@LKI

解决办法如下:

  • wechatpy用到的请求方法是requests.Session(), 查看requests.Session()文档可以知道,我们要传入解密后的文档路径
  • 我们只要按照下列步骤进行解密(密码是商户id),生成一个解密的证书(apiclient_cert.pem),就能够直接使用了:
openssl pkcs12 -in apiclient_cert.p12 -nodes -out apiclient_cert.pem 

@messense
Copy link
Member

messense commented Dec 4, 2017

一般微信支付申请成功之后邮件里面就已经有了 key 和 cert 的 pem 文件好像。

@MIA503
Copy link
Contributor Author

MIA503 commented Dec 4, 2017

对的,微信文档上说除PHP以外的开发都用apiclient_cert.p12,但是使用之前要先解密

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants