管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
1 ]( L5 ^, X7 |, P }4 M8 G& o, A1.添加商品信息0 U4 ?+ J3 W' {6 A& j; ^5 z
2.添加图片" u n" w( k C$ O3 p ]
3.查询所有产品
* C7 ?# W8 F! a2 b4.查询某个具体产品信息9 f" L# U$ @; R+ h
5.删除某个产品
0 T' E$ V) ^5 \: Q3 g9 D6.删除图片% Y1 S1 u+ j' ^. X- s
7.图像识别2 O4 Q2 O+ J+ q$ d
; l& S5 U+ O- [图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey' ?' a4 |/ c. o1 c7 p& f# W" J
1 V) h% y8 @: h- k8 q
PHP示例:
1 E$ R% z+ K% ?$ x3 w- <!--?php
* H7 h6 F) a6 m* z1 g/ q, ]+ A7 n - // +----------------------------------------------------------------------
& Q2 j) c& o6 F4 D+ f - // | JuhePHP [ NO ZUO NO DIE ]
, S' s7 u8 ?' f8 S - // +----------------------------------------------------------------------4 u/ h6 y" L6 _; x% s l4 g0 S
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
0 u6 ]8 |5 L) D6 G o; R0 m - // +----------------------------------------------------------------------' u+ _, q4 O+ f1 d s: G# B' b
- // | Author: Juhedata <info@juhe.cn-->% x* \4 `+ @7 V' h) k) Y+ \
- // +----------------------------------------------------------------------. P1 B- J7 \1 u( y9 R& C
- / _" V/ n1 j1 A' Y
- //----------------------------------: U* [" @8 q) T( e2 W$ I! V
- // 图像识别调用示例代码 - 聚合数据
, `' w5 d6 T' \ A; ~ - // 在线接口文档:http://www.juhe.cn/docs/117
- d7 X7 D; u$ k+ f - //----------------------------------
0 C# S4 \3 v. e( l7 F: Q -
) I% c2 x$ z- L7 ] - header('Content-type:text/html;charset=utf-8');
8 c) s- Z5 F2 e4 a B# z - 2 }4 J, l1 ^) X. M" K, J5 w
- , C9 v; L/ E3 e( p! U
- //配置您申请的appkey8 F" ` e4 r3 H4 X1 e- ^
- $appkey = "*********************";
, [# g- i; n$ z: q; Q9 ~0 B8 m* r! c6 u8 \ - " u6 D* Y% b4 s; d( k/ X$ G$ w7 T8 A
- 9 L* X5 g- A: M5 p
-
0 T0 j, V8 z; \3 Q+ L -
5 l4 _1 V" q' U' K" F - //************1.图像上传************
1 j4 W, u& |- M7 |6 T - $url = "http://japi.juhe.cn/image_recognition/upload";
% Z3 }- J8 T3 m4 O/ ? - $params = array(
* T% Q# ^& |# c2 Y& O$ [ - "file" => "",//上传的单张图片4 O) d g! r* W# k5 O7 v `
- "key" => $appkey,//APP Key
$ K6 A4 \. W; y* j( h n' z3 H - "pname" => "",//包名
; | y4 P& K% [ S+ r - );
: \" M* M7 w" r4 P# t) T' } - $paramstring = http_build_query($params);
( R0 Q2 H7 H; E" N, W - $content = juhecurl($url,$paramstring,1);
2 q. @$ S6 i3 z1 ^8 N - $result = json_decode($content,true);! Q: X0 {% D" N6 K7 }
- if($result){
. ~0 M: z) u3 K N# n - if($result['error_code']=='0'){
6 Y F7 R0 w9 D8 K - print_r($result);, }3 [% s- J$ Z, k. o' _
- }else{
- y1 |" W+ c+ u# ]$ c2 h% k - echo $result['error_code'].":".$result['reason'];
6 g' B/ \0 e( x/ _1 B! V; ]5 p - }* j$ R; E# c9 ]9 z( H5 G/ D
- }else{7 V) t- O, d' E$ i
- echo "请求失败";
1 x6 m2 n* u7 X9 P3 Q - }
! O4 c* R! n6 w1 C) J* a( C - //**************************************************# E& n7 |" H( o
- 1 ?! b7 y Z2 Q# |
- 7 x2 ]7 T: w3 Z3 h6 @3 g
- 5 l9 Q; F2 b2 |, U2 _8 _
- + s' x3 [3 R- K* U
- //************2.查寻上传图像信息************
4 I& U+ B- H- q# Y8 H8 k! C3 n - $url = "http://japi.juhe.cn/image_recognition/findAll";, N$ l, K/ P2 f
- $params = array(
* W7 `* X R) Y R* V - "key" => $appkey,//APP Key
# h) _- Q5 l- j H - );
2 G/ I) T7 V9 g+ [ - $paramstring = http_build_query($params);
' V0 c8 Y% Q2 L& | - $content = juhecurl($url,$paramstring);
% c4 R; Q- [3 N5 m& R; Y2 w - $result = json_decode($content,true);
9 N2 Z$ v- A6 g9 N - if($result){9 N' ^: N$ @( S7 r- I
- if($result['error_code']=='0'){: v ^/ O w/ E& ]
- print_r($result);( ^7 `. w9 F) D2 B) h, f( ]5 p
- }else{
7 D2 p: y+ j' S( c - echo $result['error_code'].":".$result['reason'];. h/ Q0 s( n7 ] F! M
- }* I5 H' f. M- `* C0 ?1 X
- }else{
, {0 I' a: }. t f - echo "请求失败";9 E3 Y r) C3 E" [
- }6 ~! ]% }1 \- x( i
- //**************************************************" m7 O2 a& @5 l
-
+ b0 N8 ?% i: s6 Q- f* n - . R3 F% i7 H! A5 P8 {
-
# \! J; C( ^; J6 _ - # }4 U$ ~4 { g
- //************3.删除图像信息************: I. a/ _# _7 m0 _' f; N
- $url = "http://japi.juhe.cn/image_recognition/delete";
* U F: T5 x4 z- R9 K1 p - $params = array(( v# B' V. T; d. |6 a
- "key" => $appkey,//APP Key
* M1 Q, W# a2 u2 l - "imageId" => "",//图片ID- A0 s. U" O. A8 _% g% d
- );
8 T% s9 V! ~# o: m. O - $paramstring = http_build_query($params);
5 \) F$ i0 ^6 _! ]& Z7 p - $content = juhecurl($url,$paramstring);6 ?$ y% ]4 \$ ]4 Q0 i0 a6 Z
- $result = json_decode($content,true);- m. ~" l% I9 I7 l2 s
- if($result){) _/ @) v& ~4 P( K- c; K
- if($result['error_code']=='0'){
8 l0 Z; [0 r1 O* u( u9 Q' K - print_r($result);
2 j$ m: F& y* D; X: Z5 a0 l - }else{2 R0 t% O5 Q {0 U6 s. e
- echo $result['error_code'].":".$result['reason'];9 H+ w9 a$ \0 R2 B6 ?* [- u0 R
- }+ u' D- f# n$ I6 i; O& S
- }else{. c' @: u$ O6 X7 g$ d: W
- echo "请求失败";
$ T( y2 Y( w& x) B9 f/ n/ h" D {, y - }
3 Z$ F8 S$ f6 [( K: ] - //**************************************************
. a$ ?" y+ J% I# V -
7 j# E& i; K( N$ Z. a7 D4 u -
+ `- I) s4 a6 c" z! s9 _1 v7 z - 1 W0 D+ P. T: a5 H, C) X( a- F
- - B$ B* N+ b4 J; E
- //************4.图像识别************
3 o; _$ Y- L: ~- G! l - $url = "http://japi.juhe.cn/image_recognition/check";
- x' d+ X0 A, T" b) I - $params = array(
1 q# K- w0 b }7 h5 E. [6 S - "file" => "",//上传的图片
6 t) K* z& j6 X! l - "key" => $appkey,//APP Key
/ Q: P. P3 h% W( V. z7 R/ s& b - "pname" => "",//包名
- o2 _; a0 K* F7 V, ^ - "device_name" => "",//设备名称(如android OS或iphone OS)
+ t' p8 b0 B" ?% y& V9 a - "device_version" => "",//设备版本(如:4.0.3)
' M, S' t8 B+ K* Z& C: q - "latitude" => "",//纬度
1 W- s/ ?" B+ | - "longitude" => "",//经度! b( [7 v1 X: s) v! \
- "uuid" => "",//设备id& }4 k$ Z( F1 h& J, j! W) h5 A1 ?& K
- "zone" => "",//请求地区7 z3 N4 U; a& C2 J! u
- );: m" i5 ?/ D* W( i3 X2 o2 p5 }% ?
- $paramstring = http_build_query($params);* ^: [+ B( ]( s6 r
- $content = juhecurl($url,$paramstring,1);
/ F4 X1 ]& x. P8 E - $result = json_decode($content,true);$ v+ u3 B8 g3 T1 _
- if($result){+ ]0 G, Z4 G4 f: b8 z2 e3 D6 q: P
- if($result['error_code']=='0'){
* R# Q$ b: H2 S1 r. f$ ~! ?# M1 c - print_r($result);
+ W$ w. R6 f; g- {5 K' V - }else{
! G# `) H+ O0 M) B' @; o8 { - echo $result['error_code'].":".$result['reason'];0 d* S" C* B- n; D
- }
" D9 h- F( {4 u- p - }else{# c. k3 {5 u5 ?6 A3 v4 T" i' P) t
- echo "请求失败";8 j) S3 Y+ r, I- X1 [% U8 D" S
- }& T' s/ }4 E' a0 H- }
- //**************************************************
# x7 b3 s6 Y% } -
( P3 F% V5 q- c -
6 v! N0 j! }5 @; f8 o - 1 l, R9 q- d/ J7 w7 m
-
+ W& ^% _( E' r3 s) j7 U2 y - / U" d# c) p6 V8 f* ~+ |2 i9 |
- /**
* S5 @; P Q: H! k - * 请求接口返回内容/ q3 Y9 d2 i/ D7 y
- * @param string $url [请求的URL地址]% F! r" G& B% N7 H; V& D$ F, z: n7 Q
- * @param string $params [请求的参数]
/ C A- G9 N3 F! w7 q - * @param int $ipost [是否采用POST形式]
. x" W: t$ z/ W* ] - * @return string, c! J; }! J7 P* s3 E* j& V
- */
) y" n1 e! J8 z2 l. V8 G1 b - function juhecurl($url,$params=false,$ispost=0){) K* w* v# \# ?
- $httpInfo = array();
0 X9 I2 ?8 l) U9 G' ?) H - $ch = curl_init();
% M ?7 `* B) ?- i- B& V - e8 I3 D- ^8 m# U( q
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
) y2 f0 P% T" ~ - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );% v4 j' B6 g. r+ J. g- m
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
9 u! z2 K6 N1 g - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);8 e7 K% r# v" i
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );' L7 u k+ B9 q7 ^# d3 o
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
) I+ {/ j% T4 L* d( G, N - if( $ispost )
& b( _# F6 J4 n& ^( _ - {
" C# [0 r" s, a5 I1 G# z! J8 C - curl_setopt( $ch , CURLOPT_POST , true );/ _1 @- |1 R. T) p# X: ?
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
7 g0 y7 S# |; w+ M - curl_setopt( $ch , CURLOPT_URL , $url );; k& P% W" q' ~. l' r# K
- }8 x2 R1 q% N% H) N, v6 y
- else
. L W+ I& U2 b7 n. G - {
- f- }: ~2 n6 v- j; f - if($params){
6 T, _! |2 z% ^/ F0 G* V - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
# d% {& S7 ~0 M; a+ B( u5 t - }else{
# A X# T$ s) _6 C" w) [ - curl_setopt( $ch , CURLOPT_URL , $url);9 U; x1 Q4 G3 V; z: s$ m8 A. e
- }
- g; i: {2 b0 N- g/ b - }. X% k) h+ R/ q. ^3 g2 d
- $response = curl_exec( $ch );" A6 ~' J* \6 s. A$ s4 W5 w, g
- if ($response === FALSE) {
1 h. l9 S* S: t& w6 b- Q - //echo "cURL Error: " . curl_error($ch);
/ L0 { D& T3 n5 s X% u - return false;. i$ J& c, a% c {5 k( b9 C2 U! z2 M( S, o
- }" c4 e; q% y# x/ [
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
- H: r- H6 ? t+ ^. G" X - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );: W, z2 N! ~9 S- L+ m6 ?0 Z: k
- curl_close( $ch );
; G. ~ Z5 `4 q' x) L - return $response;
. v& H3 I) F& g2 h. ?: {9 d2 f - }
复制代码
' U/ Y$ V/ q0 g
3 l# e8 L3 B; S4 w$ R) }# j, R0 ? |
|