0

私はgithubのwhatsapiとexamples/whatsapp.phpを使用しています。番号、パスワードなどを適切に設定しました...

ただし、プログラムを実行すると、ログイン後、連絡先とグループを取得するはずのユーザーを選択しようとすると、JS エラー 'エラー: AJAX 要求でエラーが発生しました. XML/Json 形式が不適切です。出てきます。

firbug コンソールを確認すると、次の php エラー メッセージが表示されました。


注意: 未定義のインデックス: C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\Landshoppe \WAPP\Chat-API-master\examples\whatsapp.phpの321行目の id
{"success":true,"タイプ":"連絡先","データ":....

それを呼び出す関数は

public function __construct(array $config)
{
    $this->config = $config;

    if ($_SERVER['REQUEST_METHOD'] == "POST") {
        try {
            $this->inputs = $this->cleanPostInputs();

            if (isset($this->inputs['from'])) {
                $this->from = $this->inputs['from'];

                if (!array_key_exists($this->from, $this->config)) {
                    exit(json_encode(array(
                        "success" => false,
                        'type' => 'contacts',
                        "errormsg" => "No config settings for user  $this->from could be found"
                    )));
                } else {
                    $this->number = $this->config[$this->from]['fromNumber'];
//  --This is the Line--   $this->id = $this->config[$this->from]['id'];
                    $this->nick = $this->config[$this->from]['nick'];
                    $this->password = $this->config[$this->from]['waPassword'];

                    $this->wa = new WhatsProt($this->number, $this->nick, false);
                    $this->wa->eventManager()->bind('onGetMessage', array($this, 'processReceivedMessage'));
                    $this->wa->eventManager()->bind('onConnect', array($this, 'connected'));
                    $this->wa->eventManager()->bind('onGetGroups', array($this, 'processGroupArray'));
                }
            }
        } catch (Exception $e) {
            exit(json_encode(array(
                "success" => false,
                'type' => 'contacts',
                "errormsg" => $e->getMessage()
            )));
        }
    }
}

その後、すべてのグループと連絡先がその中で定義されます! しかし、プログラムはJSONエラーで一時停止しています!

では、「未定義のインデックス ID」を修正するにはどうすればよいですか?

4

1 に答える 1

1

最終的に、スクリプトを保持していたのは「require_once "src/whatsprot.class.php"」であることがわかりました。「require」または「include」に変更すると、正常に動作します。私が信じる理由は、ファイルがロードされた後の json 呼び出しは 'whatsprot.class.php' ファイルを再度必要としますが、'require_once' を使用して 1 回だけロードされるため、ファイルを見つけることができなかったからです。

于 2015-12-10T11:23:16.607 に答える