管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
% ?9 l" M& z+ x1.添加商品信息
' R( O0 I4 r/ Y N0 p; j/ R2.添加图片
$ }0 ]. E6 Z- q; w* M2 {; g3.查询所有产品% Q" V: y9 O4 _9 d
4.查询某个具体产品信息" N* w1 [3 u, c0 k5 @) [$ d
5.删除某个产品3 l3 j, ^/ [/ E; |& p
6.删除图片3 V& l$ u9 N( a$ G
7.图像识别
# O0 \3 ^6 \! V4 m3 ~0 y
6 T8 b4 Y W& k' H图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
% S: `3 J, L( g8 o
7 }( N" D% W. V" Q, KPHP示例:
, d {" [# j2 P/ {6 O- <!--?php
' @9 { ?) y- Z" _3 e" @% J - // +----------------------------------------------------------------------
: Y8 y0 F& f7 \ - // | JuhePHP [ NO ZUO NO DIE ]
9 q3 \. e* I! n - // +----------------------------------------------------------------------
3 X2 f3 A0 }5 c% W3 e - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
l3 r% |6 J" t# |1 a+ T - // +----------------------------------------------------------------------# j v# h2 Y8 q$ T
- // | Author: Juhedata <info@juhe.cn-->" [! L/ u2 I, g2 x- N6 C/ B
- // +----------------------------------------------------------------------
9 ~ p! b, ]& `% X& G - , Y" O+ l# |$ U" H1 O. k
- //----------------------------------: ^6 T0 F$ ]* I1 j6 K$ Q
- // 图像识别调用示例代码 - 聚合数据
. N/ k: K; \# k, U. D+ P - // 在线接口文档:http://www.juhe.cn/docs/1174 I5 `; |" [; T
- //----------------------------------
0 @* _( _# y$ e, r -
$ T M, Y4 O9 g9 q6 U- P - header('Content-type:text/html;charset=utf-8');
; U# `: s6 M0 \7 g _! b! ? - ; P: u+ G9 H4 ^. ]
-
9 i+ ^: J4 H$ D - //配置您申请的appkey
+ {0 l e! {5 F6 r+ `. d - $appkey = "*********************";
, b- {9 ?- h. P7 L -
2 z+ p/ h; O$ _( A4 N0 A' h' a" V -
x" Q3 ]2 v+ i H - " |5 d2 j2 Q: S7 l' d
- 2 T3 P& w( u6 o! {+ r5 O
- //************1.图像上传************2 R- ^! d. j% D2 f! P! g
- $url = "http://japi.juhe.cn/image_recognition/upload";
! I$ @( ^( _1 Y7 _) O. P k - $params = array(" M& M1 k/ E S" S
- "file" => "",//上传的单张图片
# A- V4 h6 K$ ~# ^ - "key" => $appkey,//APP Key
+ `8 C! x# H$ c% z7 e - "pname" => "",//包名
1 Y0 l% L) q5 _$ }3 r - );* M8 e: n+ m" ?
- $paramstring = http_build_query($params);
' Q- g9 f( u* C" n; x. Q& S - $content = juhecurl($url,$paramstring,1);! M) j w' S! ?9 o5 \3 _
- $result = json_decode($content,true);# ~1 b: Y- q2 ~, `
- if($result){) P% F# Q" W ~
- if($result['error_code']=='0'){2 o9 k: I4 a3 n, G4 K2 q! e
- print_r($result);9 @% a! S) U& g' y6 g/ }2 @
- }else{
# s. T3 j+ K: W1 [ - echo $result['error_code'].":".$result['reason'];
: s# u+ Q( r7 }/ p& y - }
# c- Y2 h( o, Y - }else{& x6 D) P5 a2 K3 ?: W3 ~8 e
- echo "请求失败";
/ M4 g( X& ^! e; x - }
0 W# X# D- `4 c( ^0 s - //**************************************************
8 @. p7 T$ I7 N V( M - ' V; a9 o4 ]! i. c. r9 m
-
6 D* F4 @& `! h0 c8 L5 n1 C/ J -
* U/ Y' T$ c* ~* k% ] -
- s- i0 T& e3 ?$ j - //************2.查寻上传图像信息************
2 [! `! V1 f% d. P - $url = "http://japi.juhe.cn/image_recognition/findAll";% n0 R' \/ m. L! ^+ {
- $params = array(( j& Q1 p* j7 K+ _
- "key" => $appkey,//APP Key4 H+ F$ ^4 C. v+ ^3 B3 J5 W
- );
: P' Z" B% e0 C, m9 V# [ - $paramstring = http_build_query($params);
+ v# [2 U, [# q) H5 s - $content = juhecurl($url,$paramstring);
! Q3 Z/ N; G% l7 `" _! c - $result = json_decode($content,true);
- L% a' N+ u N- b0 c. D - if($result){
. \( m# j7 D7 v& b& g" k5 L+ K' r - if($result['error_code']=='0'){) \' @, c7 J$ ^1 S) U, M7 ^
- print_r($result);! h# T4 K6 k3 t+ r
- }else{
5 F% G. N0 d$ {8 @, z! Q! w - echo $result['error_code'].":".$result['reason'];
\0 O5 m" v, u1 Q Y6 G0 F& C - }0 G) E1 R; q2 M* \) ?1 D# ?( Z
- }else{- W. h" u2 Z' n! Y
- echo "请求失败";8 ?3 W3 I0 B8 x# @6 x5 r
- }
8 _0 O3 ~; {& \4 ` - //**************************************************
/ E9 `: Q. e$ \ -
& M) ^5 I; F5 x -
" a* a- @1 w/ n4 j, Z" V3 b - 2 x" \, \4 b9 F1 H9 }
-
% L$ n9 t( w/ _. X9 w s - //************3.删除图像信息************( [9 k2 w4 l* z/ C. p
- $url = "http://japi.juhe.cn/image_recognition/delete";2 |$ u Q6 z: Q; f. t
- $params = array(
1 p9 x0 v" T n8 J$ \ - "key" => $appkey,//APP Key
' \, z7 o8 Q( N/ F0 X& D - "imageId" => "",//图片ID: A0 [/ ]7 s& k
- );1 ]2 U9 J4 S$ `- p
- $paramstring = http_build_query($params);
9 |! p1 U' l" x) N+ b( n2 i% T- F - $content = juhecurl($url,$paramstring);
3 N) Z5 _4 e' v3 I0 C# I! t# g& | - $result = json_decode($content,true);/ ]" F7 N& m A* T
- if($result){: C! M# s1 m2 W
- if($result['error_code']=='0'){3 f: L: Q# b6 K
- print_r($result);" K, A; C2 m O' d5 ?" C8 {/ u
- }else{( H2 ~' _( B0 t- k0 t( y
- echo $result['error_code'].":".$result['reason'];3 p# `0 }$ e" Z5 E8 g" Y
- }
% K, X2 |* l4 Y6 Y5 o9 D% J - }else{1 T6 G6 q) }5 f/ j X
- echo "请求失败";" v/ K: p! E9 W2 R* W2 V
- }
9 `. r8 q2 G5 s% t - //**************************************************
' A" I5 ^4 A3 K& C7 k - " w4 [$ H( `* f' }0 z
-
+ y' o* Q; \9 M -
$ g* z- F# a* g" c/ ?2 k -
' x; |& c9 i* c& N) R. R - //************4.图像识别************+ l! O. ] S# E
- $url = "http://japi.juhe.cn/image_recognition/check";
2 ]& l2 f/ }" ~6 z - $params = array(
( O+ }6 Y; O8 }, u9 K; m7 ~ - "file" => "",//上传的图片6 m |5 J# F2 b6 O* W9 Q
- "key" => $appkey,//APP Key
- M2 e' C0 W* C i+ F& X - "pname" => "",//包名# {" H P# O6 h3 L
- "device_name" => "",//设备名称(如android OS或iphone OS)
' @1 n$ w Z& |% M* C% U8 l4 [& O, Q - "device_version" => "",//设备版本(如:4.0.3)7 R5 A3 l G5 a1 |1 `0 F
- "latitude" => "",//纬度5 [8 a6 j* J6 `5 g
- "longitude" => "",//经度 p1 q5 [9 T: \1 w8 z
- "uuid" => "",//设备id
0 U) H T: o9 E3 G0 k: U* s: y - "zone" => "",//请求地区( R+ O4 |5 o! r' w* J9 j# s: r8 L0 x
- );
9 o% }; H1 B6 }7 ^0 d- _% J - $paramstring = http_build_query($params);1 {! r6 ?) J) o! g
- $content = juhecurl($url,$paramstring,1);
+ T' [2 l: X9 W* s - $result = json_decode($content,true);
. s" Q z3 [ W/ K - if($result){" n6 b+ f: D" L+ O
- if($result['error_code']=='0'){
" \ ^; I6 x7 ] - print_r($result);
4 _! c* V) }& s3 ]) @9 D - }else{5 S3 p, D9 t/ Z; Q; t; A
- echo $result['error_code'].":".$result['reason'];
4 O1 Y) O1 h! I; c - }) {, d1 I( V' ~7 ^4 x
- }else{/ h) f) E. v+ ^0 @* J6 X
- echo "请求失败";
1 o# V% I+ L, N$ _0 _3 y - }
- B3 v1 O. r7 H, j0 Q( F - //**************************************************
! @2 V+ A) K. K9 [5 M - u/ j( v& `* _. z$ s1 Z* V
- 3 e2 S" _; U8 D9 Y z
-
. ^8 m. Y3 g. G/ Q) I1 {" V+ K - 5 `9 U; \$ s% ]5 d" d
- ! j' X8 N4 A" d% ?/ `9 [2 g
- /**
8 W; ~5 c$ U( D: B4 w) L8 l - * 请求接口返回内容4 o1 F. C7 Y9 s6 B! ~/ [3 f% g
- * @param string $url [请求的URL地址]( [% ?# l( _+ l4 G$ t. J
- * @param string $params [请求的参数]
5 r7 R; p; D8 D/ W" y$ Q+ s - * @param int $ipost [是否采用POST形式]
P0 ^# [' ^8 I1 ^0 ^% M+ Q - * @return string
) z/ x# x" B# M1 Q5 W# K" z$ ]' V3 K - */
- E; p# j# i$ R - function juhecurl($url,$params=false,$ispost=0){6 d" y1 l" w+ e+ ?' _% g' i* X6 o
- $httpInfo = array();8 _$ X# A5 N* Q9 Q
- $ch = curl_init();
9 h9 l9 D5 R& L/ [ - / O9 I) E+ C/ M# |3 A
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );5 Q8 [9 A T) U. ~
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );. \- K2 ?6 q x. _5 I
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );) ~4 Y# s8 b! K2 T
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
: k1 Y; L3 I# b - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );; L" O' }, b5 e
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);( x+ _. ?3 @ s I
- if( $ispost )1 g2 G- ]% I4 p+ V* m) ]
- {
) h- S5 \! ~2 M& ^, S% m7 } - curl_setopt( $ch , CURLOPT_POST , true );4 ^$ w# @$ A" a0 ~% Q) e
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );- d5 R- s# h) q9 o/ t8 {- N/ t
- curl_setopt( $ch , CURLOPT_URL , $url );
, ]9 m" l# B8 p6 [ - }
2 H& I+ \; c; D3 G s% H- x8 } - else1 w! y$ a9 c |( Q' x2 n
- {5 q$ U t3 k3 k* L& D6 \: H ~
- if($params){
: S3 s# B% L6 F M9 |$ N; s - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );4 `0 {3 M5 ~/ v& E9 o( p
- }else{- e5 D) Q# U# X1 l
- curl_setopt( $ch , CURLOPT_URL , $url);
9 c& z6 E9 C7 u* e! ~! |! C - }8 e5 E" S( V: a' }6 j0 \$ w
- }8 K0 j$ r/ ]' H4 `7 m
- $response = curl_exec( $ch );% W7 X, R3 ]+ C5 P+ b
- if ($response === FALSE) {: @* k. ^2 I% \( ]' |
- //echo "cURL Error: " . curl_error($ch);
" Q. `( H4 i6 W* l& [. a - return false;
) C8 e5 n6 N' V& ]. K* \4 g - }
3 y; A5 K( ^+ p8 t5 l& X - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
$ Z5 D" I3 G7 D) |: v! [) N( U - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
( B) E ]8 C% G5 U3 w6 t4 K - curl_close( $ch );
0 n% v% R" v0 }0 D' E - return $response;1 q( ~1 r7 e9 l: k/ \
- }
复制代码 , n* a9 N! {2 y# w- o
, U8 i: ]% U$ P/ `& V4 ~" \& |9 y8 K
|
|