PHP-微信提现到零钱

PHP-微信提现到零钱
哈喽大家好,在原来做的微信支付的各种接口里总会不经意的就踩个地雷,虽然都是小问题,但是还是会浪费一些时间,于是乎,今儿个心血来潮就写一个关于微信提现到零钱【俗称企业付款到零钱】互相探讨,大佬轻喷哈

一.使用条件

在这里插入图片描述
在这里插入图片描述
切记切记不要在用到提现的时候再去开通

二:程序
先做一个调用支付的类
class WxpayService
{
protected $mchid;
protected $appid;
protected $appKey;
protected $apiKey;
public $data = null;

public function __construct($mchid, $appid, a p p K e y , appKey, appKey,key)
{
$this->mchid = $mchid;
$this->appid = $appid;
$this->appKey = $appKey;
$this->apiKey = $key;
}

获取OpenId,用于后续的给对应的用户进行提现
/**

  • 通过跳转获取用户的openid,跳转流程如下:
  • 1、设置自己需要调回的url及其其他参数,跳转到微信服务器https://open.weixin.qq.com/connect/oauth2/authorize
  • 2、微信服务处理完成之后会跳转回用户redirect_uri地址,此时会带上一些参数,如:code
  • @return 用户的openid
    */
    public function GetOpenid()
    {
    //通过code获得openid
    if (!isset($_GET[‘code’])){
    //触发微信返回code码
    $scheme = $_SERVER[‘HTTPS’]==‘on’ ? ‘https://’ : ‘http://’;
    b a s e U r l = u r l e n c o d e ( baseUrl = urlencode( baseUrl=urlencode(scheme. S E R V E R [ ′ H T T P H O S T ′ ] . _SERVER['HTTP_HOST']. SERVER[HTTPHOST]._SERVER[‘PHP_SELF’].$_SERVER[‘QUERY_STRING’]);
    $url = KaTeX parse error: Expected group after '_' at position 7: this->_̲_CreateOauthUrl…baseUrl);
    Header(“Location: $url”);
    exit();
    } else {
    //获取code码,以获取openid
    $code = $_GET[‘code’];
    $openid = t h i s − > g e t O p e n i d F r o m M p ( this->getOpenidFromMp( this>getOpenidFromMp(code);
    return $openid;
    }
    }

/**

  • 通过code从工作平台获取openid机器access_token
  • @param string $code 微信跳转回来带上的code
  • @return openid
    /
    public function GetOpenidFromMp($code)
    {
    $url = KaTeX parse error: Expected group after '_' at position 7: this->_̲_CreateOauthUrl…code);
    r e s = s e l f : : c u r l G e t ( res = self::curlGet( res=self::curlGet(url);
    //取出openid
    d a t a = j s o n d e c o d e ( data = json_decode( data=jsondecode(res,true);
    $this->data = $data;
    $openid = $data[‘openid’];
    return $openid;
    }
    /
    *
  • 构造获取open和access_toke的url地址
  • @param string $code,微信跳转带回的code
  • @return 请求的url
    */
    private function __CreateOauthUrlForOpenid($code)
    {
    $urlObj[“appid”] = $this->appid;
    $urlObj[“secret”] = $this->appKey;
    $urlObj[“code”] = $code;
    $urlObj[“grant_type”] = “authorization_code”;
    $bizString = t h i s − > T o U r l P a r a m s ( this->ToUrlParams( this>ToUrlParams(urlObj);
    return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
    }

/**

  • 构造获取code的url连接
  • @param string $redirectUrl 微信服务器回跳的url,需要url编码
  • @return 返回构造好的url
    */
    private function __CreateOauthUrlForCode($redirectUrl)
    {
    $urlObj[“appid”] = $this->appid;
    u r l O b j [ " r e d i r e c t u r i " ] = " urlObj["redirect_uri"] = " urlObj["redirecturi"]="redirectUrl";
    $urlObj[“response_type”] = “code”;
    $urlObj[“scope”] = “snsapi_base”;
    $urlObj[“state”] = “STATE”."#wechat_redirect";
    $bizString = t h i s − > T o U r l P a r a m s ( this->ToUrlParams( this>ToUrlParams(urlObj);
    return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
    }

/**

  • 拼接签名字符串
  • @param array $urlObj
  • @return 返回已经拼接好的字符串
    */
    private function ToUrlParams($urlObj)
    {
    b u f
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值