wxxcx
1.0.0
ミニプログラムの公式暗号化および復号化 SDK はすでに非常に明確ですが、Laravel スタイルに変更されており、まさにレンガ職人のようなものです。車輪の再発明に関しては、他の人の拡張機能にはユーザー情報を復号するときにコードエラーがあることがわかり、Laravel Curl 拡張機能をインストールする必要性については言及されていませんでした。他の拡張機能に依存せず、ソース コードに基づいて自分で 0.0 を作成し、直接インストールして使用する必要がありました。
PHP7.1の暗号化関数
mcrypt_module_open()
は廃止されたため廃止されました。 PHP7.1バージョンを使用している人はバージョン2.0のコードをインストールしてください。
次のコマンドを実行して、最新の安定バージョンをインストールします。
PHP < 7.1
composer require iwanli/wxxcx=1. *
PHP > 7.1
composer require iwanli/wxxcx=2. *
または、 composer.json
ファイルに次の情報を追加します。
PHP < 7.1
"iwanli/wxxcx" : " ^1.0 "
PHP > 7.1
" iwanli/wxxcx " : " ^2.0 "
次に、サービスプロバイダーを Laravel の特定の場所に登録します: /config/app.php
のproviders
配列:
Iwanli Wxxcx WxxcxServiceProvider::class,
設定ファイルを公開します。
php artisan vendor:publish --tag=wxxcx
コマンドが完了すると、 wxxcx.php
構成ファイルが構成フォルダーに追加されます ( /config/wxxcx.php
など)。
構成ファイルを生成したら、ミニ プログラムのAppID
とAppSecret
を/config/wxxcx.php
ファイルに入力します。
. . .
use Iwanli Wxxcx Wxxcx ;
class WxxcxController extends Controller
{
protected $ wxxcx ;
function __construct ( Wxxcx $ wxxcx )
{
$ this -> wxxcx = $ wxxcx ;
}
/**
* 小程序登录获取用户信息
* @author 晚黎
* @date 2017-05-27T14:37:08+0800
* @return [type] [description]
*/
public function getWxUserInfo ()
{
//code 在小程序端使用 wx.login 获取
$ code = request ( ' code ' , '' );
//encryptedData 和 iv 在小程序端使用 wx.getUserInfo 获取
$ encryptedData = request ( ' encryptedData ' , '' );
$ iv = request ( ' iv ' , '' );
//根据 code 获取用户 session_key 等信息, 返回用户openid 和 session_key
$ userInfo = $ this -> wxxcx -> getLoginInfo ( $ code );
//获取解密后的用户信息
return $ this -> wxxcx -> getUserInfo ( $ encryptedData , $ iv );
}
}
ユーザー情報の返信形式:
{
"openId": "xxxx",
"nickName": "晚黎",
"gender": 1,
"language": "zh_CN",
"city": "",
"province": "Shanghai",
"country": "CN",
"avatarUrl": "http://wx.qlogo.cn/mmopen/xxxx",
"watermark": {
"timestamp": 1495867603,
"appid": "your appid"
}
}
//调用登录接口
wx . login ( {
success : function ( response ) {
var code = response . code
wx . getUserInfo ( {
success : function ( resp ) {
wx . request ( {
url : 'your domain' ,
data : {
code : code ,
iv : resp . iv ,
encryptedData : resp . encryptedData
} ,
success : function ( res ) {
console . log ( res . data )
}
} )
}
} )
} ,
fail : function ( ) {
...
}
} )
バグがある場合は、「問題」で報告してください。ありがとうございます。