code-lives / weixin
微信小程序、公众号、H5、App(支付、手机号解密、获取Token、模版消息、支付异步通知、退款、订单查询)
1.0.0
2023-07-26 08:37 UTC
README
安装
composer require code-lives/weixin 1.0.0
⚠️ 注意
金额单位分 100=1 元
返回结果 array 由开发者自行判断
预下单
//引入命名空间 use Applet\Assemble\Weixin; // 微信小程序 $pay= Weixin::init($config)->set("订单号","金额","描述","描述")->getParam(); // 微信公众号【appid 和secret 换成公众号的】 $pay= Weixin::init($config)->set("订单号","金额","描述","openid")->getParam(); // 微信H5【appid 和secret 换成公众号的】 $pay= Weixin::init($config)->set("订单号","金额","描述")->getH5Param(); // 微信APP (没有openid) $pay= Weixin::init($config)->set("订单号","金额","描述")->getParam();
Config
Token
$data= Weixin::init($config)->getToken();
Openid
$code=""; $data= Weixin::init($config)->getOpenid($code);
解密手机号
$data= Weixin::init($config)->decryptPhone($session_key, $iv, $encryptedData); echo $phone['phoneNumber'];
订单查询
$data = Weixin::init($config)->findOrder("订单号");
退款
$order = [ 'out_trade_no' => '123', 'total_fee' => 0.01, 'out_refund_no' => time(), 'refund_fee' => 0.01, ]; $data= Weixin::init($config)->applyOrderRefund($order);
模版消息
$data = [ "touser" => "", "template_id" => "", "page" => "pages/index/index", "miniprogram_state" => "developer", "lang" => "zh_CN", "data" => [ 'thing6' => ['value' => "第一个参数{{thing6.DATA}}"], 'thing7' => ['value' => "第二个参数{{thing7.DATA}}"], 'time8' => ['value' => "第三个参数{{time8.DATA}}"], ], $data= Weixin::init($config)->sendMsg($data,$token); $data=[ "errcode" => 0 "errmsg" => "ok" "msgid" => 123456 ]
支付回调
$pay = Weixin::init($config); $status = $pay->notifyCheck();//验证 if($status){ $order = $pay->getNotifyOrder();//订单数据 //$order['out_trade_no']//平台订单号 //$order['transaction_id']//微信订单号 echo 'success';exit; }