PHP code example of higreen / php-api
1. Go to this page and download the library: Download higreen/php-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
higreen / php-api example snippets
use Higreen\Api\Weixin\Mini;
$Mini = new Mini([
'app_id' => '小程序ID',
'app_secret' => '小程序密钥',
]);
$session = $Mini->code2session($code);
$access_token = $Mini->getAccessToken();
$res = Mini::getWXACodeUnlimit($access_token, [
'scene' => '[str] [必填] [最大32个可见字符]',
'page' => '[str] [可选] [已经发布的小程序存在的页面]',
'width' => '[int] [可选] [二维码的宽度,单位 px,最小 280px,最大 1280px]',
'auto_color' => '[bol] [可选] [自动配置线条颜色]',
'line_color' => '[arr] [可选] [auto_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十进制表示]',
'is_hyaline' => '[bol] [可选] [是否需要透明底色]',
]);
$res = Mini::sendUniformMessage($access_token, [
'touser' => '[必填] [str] [用户openid,可以是小程序的openid,也可以是mp_template_msg.appid对应的公众号的openid]',
'appid' => '[必填] [str] [公众号appid,要求与小程序有绑定且同主体]',
'template_id' => '[必填] [str] [公众号模板id]',
'url' => '[必填] [str] [公众号模板消息所要跳转的url]',
'data' => '[必填] [arr] [模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }]',
'pagepath' => '[可选] [str] [点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。]',
]);
$data = Mini::decryptData($encryptedData, $session_key, $iv);
use Higreen\Api\Weixin\MiniSecurity;
$bool = MiniSecurity::checkImg($access_token, '图片链接');
$bool = MiniSecurity::checkText($access_token, '文字内容');
use Higreen\Api\Weixin\MiniOcr;
$res = MiniOcr::bankcard($access_token, '图片链接');
$res = MiniOcr::businessLicense($access_token, '图片链接');
$res = MiniOcr::driverLicense($access_token, '图片链接');
$res = MiniOcr::idcard($access_token, '图片链接');
$res = MiniOcr::printedText($access_token, '图片链接');
$res = MiniOcr::vehicleLicense($access_token, '图片链接');
use Higreen\Api\Weixin\Offi;
$Offi = new Offi([
'app_id' => '公众号ID',
'app_secret' => '公众号密钥',
]);
$session = $Offi->code2session($code);
$access_token = $Offi->getAccessToken();
$userinfo = Offi::getUserinfo($access_token, 'openid');
$ticket = Offi::getJsapiTicket($access_token);
$config = Offi::getJsapiConfig($ticket, '网页的URL(可选)')
$res = Offi::sendMessage($access_token, [
'touser' => '[str] [必填] [接收者openid]',
'template_id' => '[str] [必填] [模板ID]',
'data' => '[arr] [必填] [模板数据]',
]);
$bool = Offi::isFollow($access_token, 'openid');
use Higreen\Api\Weixin\Pay;
$Pay = new Pay([
'mch_id' => '商户ID',
'mch_key_v3' => '商户密钥V3',
'sslcert' => '证书路径',
'sslkey' => '证书密钥路径',
]);
$res = $Pay->order('交易类型(大小写不限):JSAPI,APP,H5,Native', [
'appid' => '[str] [必填] [微信生成的应用ID]',
'description' => '[str] [必填] [商品描述]',
'out_trade_no' => '[str] [必填] [商户系统内部订单号,同一个商户号下唯一]',
'total' => '[int] [必填] [订单总金额,单位为分]',
'notify_url' => '[int] [必填] [直接可访问的URL,不允许携带查询串,要求必须为https]',
'attach' => '[str] [可选] [附加数据,在查询API和支付通知中原样返回]',
'openid' => '[str] [可选] [JSAPI交易类型必传,用户在商户appid下的唯一标识]',
'type' => '[str] [可选] [H5交易类型必传,场景类型 示例值:iOS, Android, Wap]',
]);
$res = $Pay->orderResult('商户系统内部订单号');
$res = $Pay->refund([
'out_trade_no' => '[str] [必填] [原支付交易对应的商户订单号]',
'out_refund_no' => '[str] [必填] [商户系统内部的退款单号,商户系统内部唯一]',
'total' => '[int] [必填] [原支付交易的订单总金额,币种的最小单位]',
'refund' => '[int] [必填] [退款金额,币种的最小单位]',
'reason' => '[str] [可选] [退款原因]',
'notify_url' => '[str] [可选] [异步接收微信支付退款结果通知的回调地址]',
]);
$res = Pay::decryptResource('商户号APIV3密钥', '加密报文');
use Higreen\Api\Weixin\Transfer;
$Transfer = new Transfer([
'mch_id' => '商户ID',
'mch_key' => '商户密钥',
'sslcert' => '证书路径',
'sslkey' => '证书密钥路径',
]);
$res = $Transfer->balance([
'partner_trade_no' => '[str] [必填] [商户订单号]',
'mch_appid' => '[str] [必填] [商户账号appid]',
'openid' => '[str] [必填] [用户openid]',
'amount' => '[int] [必填] [企业付款金额,单位为分]',
'desc' => '[str] [必填] [企业付款备注]',
're_user_name' => '[str] [可选] [收款用户姓名]',
]);
use Higreen\Api\Alipay\Mini;
$Mini = new Mini($init);
use Higreen\Api\Alipay\Pay;
$Pay = new Pay($init);
$res = $Pay->app([
'subject' => '交易标题',
'out_trade_no' => '商户订单号',
'total_amount' => '订单总金额,单位为人民币(元)',
]);
$res = $Pay->mini([
'subject' => '交易标题',
'out_trade_no' => '商户订单号',
'total_amount' => '订单总金额,单位为人民币(元)',
'buyer_id' => '支付宝用户的唯一userId',
]);
$res = $Pay->qrcode([
'subject' => '交易标题',
'out_trade_no' => '商户订单号',
'total_amount' => '订单总金额,单位为人民币(元)',
]);
use Higreen\Api\Aliyun\Sms;
$init = [
'id' => '应用Access Key ID',
'secret' => '应用Access Key Secret',
'sign' => '短信签名',
];
$Sms = new Aliyun($init);
$res = $Sms->send($phones, $template, $params);
use Higreen\Api\Baidu\Speech;
$init = [
'api_key' => '[str] [必填] [应用公钥]',
'secret_key' => '[str] [必填] [应用密钥]',
];
$Speech = new Speech($init);
$access_token = $Speech->getAccessToken();
$res = $Speech->text2audio($access_token, [
'text' => '[str] [必填] [文字]',
]);
use Higreen\Api\Tencent\Sms;
$init = [
'id' => '密钥 ID',
'key' => '密钥 KEY',
'app_id' => '短信应用 SDKAppID',
'sign' => '短信签名',
];
$Sms = new Sms($init);
# 发送单个手机号
$res = $Sms->sendSingle($template, $phone, $params);
# 发送多个手机号
$res = $Sms->sendMulti($template, $phones, $params);
use Higreen\Api\Tencent\Map;
$Map = new Map('key');
$res = $Map->locateByAddress($address);
$res = $Map->locateByIp($ip);
$res = $Map->locateByCoordinate($longitude, $latitude);
$res = $Map->getDistrict($id = 0);// 子级行政区划
use Higreen\Api\Tencent\Faceid;
$Faceid = new Faceid([
'id' => '密钥 ID',
'key' => '秘钥 KEY',
]);
$bool = $Faceid->verifyNameNumber('姓名', '身份证号码');
use Higreen\Api\Yidong\NumIdentify;
$init = [
'app_id' => 'APPID',
'app_key' => 'APPKEY',
'public_key' => '平台公钥',
'private_key' => '应用私钥.创建应用时,请使用同一对密钥',
];
$NumIdentify = new NumIdentify($init);
bash
composer
$bool = $NumIdentify->isDevicePhone('未实现');